Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/333.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
Pool.map的Python函数参数_Python_Multiprocessing_Pool - Fatal编程技术网

Pool.map的Python函数参数

Pool.map的Python函数参数,python,multiprocessing,pool,Python,Multiprocessing,Pool,在这种情况下,我如何指定urlretrieve的文件名?如果您想指定多个参数,并且不想在函数urlretrieve(您也没有访问权限)中对它们进行解压缩,那么您可以尝试使用starmap。例如,这里我们同时传递url和文件名: from multiprocessing import Pool from urllib.request import urlretrieve tmp= Pool(4).map(urlretrieve, urls) 您已经传递了URL参数。让你的问题更清

在这种情况下,我如何指定urlretrieve的文件名?

如果您想指定多个参数,并且不想在函数
urlretrieve
(您也没有访问权限)中对它们进行解压缩,那么您可以尝试使用
starmap
。例如,这里我们同时传递
url
文件名

 from multiprocessing import Pool
 from urllib.request import urlretrieve     
 tmp= Pool(4).map(urlretrieve, urls)

您已经传递了
URL
参数。让你的问题更清楚是的,但是
url
在urlretrieve中用作
url
。我还想再次指定文件名,用需要请求的所有输入文件名更新您的问题,避免混淆
from multiprocessing import Pool
from urllib.request import urlretrieve
urls = ["http://www.google.com", "http://www.yahoo.com"]
filenames = ["google.html", "yahoo.html"]
results = Pool(2).starmap(urlretrieve, zip(urls, filenames))