python - 如何将多个参数传递给 ThreadPoolExecutor executor.map()?
问题描述
那么问题是我有一个像这样的列表:[{'Title':'asdada', 'Seasons':[{'Number': 1, 'Id':'243sfs2'}, {'Number': 2, 'Id':'434sdfsdf'}]}]
包含如上所述的多个字典,问题是我需要使用所有 seasons['Id'] 对 API 执行多个请求(是的,它是一个刮板),所以我需要使用 ThreadPoolExecutor 因为列表很大. 发出请求并抓取所有数据的函数是:
def get_episodes(self, seasons): for season in seasons: season_id = season['Id'] url = f'https//asdads/{season_id} response = requests.get(url).json()
如您所见,该函数接收参数“seasons”,它是主要列表中每个元素的键“Seasons”。问题是我不知道如何使用每个迭代的这个键,就像执行器中的参数一样
with ThreadPoolExecutor(max_workers=3) as executor: executor.map(self.get_episodes('Season' values here), iterable_list)
是否有可能通过这个论点?
解决方案
推荐阅读
- c# - 如何从 .csv 文件中删除损坏的数据?
- express - 为什么 Apollo Server 不是 Express 的中间件,而是接受 Express 作为中间件的服务器?
- javascript - 如何使用 vuejs 2 转换数组中的数据?
- arrays - 返回数组索引第一个值的函数不缺少 SAS
- html - 使用 Flex 在父级中居中,而不考虑兄弟级
- javascript - 计算机属性“有时”不刷新 - 强制重新加载? - Vue JS
- mongodb - 为什么单调递增的分片键会导致插入被路由到以 maxkey 为上限的块?
- linux - 如何更改远程构建机器 Visual Studio 2017
- json - 使用 Twig 或 Grunt 从 JSON 数组创建导航
- javascript - HTML - 单击按钮获取表格单元格值