Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在python中将参数从文件添加到给定URL_Python_Python 2.7 - Fatal编程技术网

在python中将参数从文件添加到给定URL

在python中将参数从文件添加到给定URL,python,python-2.7,Python,Python 2.7,我想使用给定的URL和txt文件中的一些参数生成一系列URL 例如,给定的URL是: http://stackoverflow.com/questions/ask1 http://stackoverflow.com/questions/ask2 它们分别存储在url.xlsx文件的Sheet1中的A1和A2中 参数存储在params.txt文件中,包含以下内容: w3e 1 123456 fy 我想生成如下URL: http://stackoverflow.com/questions/ask

我想使用给定的URL和txt文件中的一些参数生成一系列URL

例如,给定的URL是:

http://stackoverflow.com/questions/ask1
http://stackoverflow.com/questions/ask2
它们分别存储在url.xlsx文件的Sheet1中的A1和A2中

参数存储在params.txt文件中,包含以下内容:

w3e
1
123456
fy
我想生成如下URL:

http://stackoverflow.com/questions/ask1/param.x
http://stackoverflow.com/questions/ask2/param.x
这意味着我将得到2x4=8个URL


你知道怎么做吗?非常感谢

将这两个文件读入列表,然后使用将它们合并:

from itertools import product

with open('urls.txt') as urlfile:
    urls = [line.strip() for line in urlfile]
以open('params.txt')作为参数文件: 参数=[line.strip()用于paramfile中的行]

for url, param in product(urls, parameters):
    print url + param