将python中的多个参数定义为一个变量

时间:2015-11-11 18:18:13

标签: python

我有超过100个不同的参数将针对单个变量进行测试。但我无法将参数指定为变量。例如:参数如下:

/master.passwd
etc/passwd
etc/shadow%00
/etc/passwd
/etc/passwd%00
../etc/passwd
../etc/passwd%00
../../etc/passwd
../../etc/passwd%00

并且每个参数都将添加到名为

的变量中
tree 

如何使用python将一个变量分配给100个参数,然后将每个参数添加到名为 tree 的变量中?我查看了list [],dict {}和一个元组(),但我没有提出解决方案。

Code example

1 个答案:

答案 0 :(得分:2)

听起来你想迭代一堆字符串并用它们做点什么?一种方法是使用列表:

url='https://10.10.20.161/IHUD/'
parameters = ["master.passwd",
    "etc/passwd",
    "etc/shadow%00",
    "/etc/passwd",
    "/etc/passwd%00",
    "../etc/passwd",
    "../etc/passwd%00",
    "../../etc/passwd",
    "../../etc/passwd%00"]

for p in parameters:
    tree = url + p
    print(tree)

输出:

https://10.10.20.161/IHUD/master.passwd
https://10.10.20.161/IHUD/etc/passwd
https://10.10.20.161/IHUD/etc/shadow%00
https://10.10.20.161/IHUD//etc/passwd
https://10.10.20.161/IHUD//etc/passwd%00
https://10.10.20.161/IHUD/../etc/passwd
https://10.10.20.161/IHUD/../etc/passwd%00
https://10.10.20.161/IHUD/../../etc/passwd
https://10.10.20.161/IHUD/../../etc/passwd%00