python - 使用带有一个参数和 self 的 pool.map 在类中调用函数:TypeError:map()缺少1个必需的位置参数:'iterable'
问题描述
我正在尝试使用池映射从同一类中的另一个函数调用一个类中的函数
pool = Pool(num_cores)
res = pool.map(self.get_data_vector())
该函数除了 self 没有参数,我收到此错误
TypeError: map() missing 1 required positional argument: 'iterable'
这是功能
def get_data_vector(self):
编辑:
我错过了要映射的变量 self.doc_ids ,它是一个列表。
我现在这样称呼它
res = pool.map(__class__.get_data_vector,(self,self.doc_ids))
该函数应该像这样调用
def get_data_vector(self, doc_id):
但现在错误变为
TypeError: get_data_vector() missing 1 required positional argument: 'doc_id'
解决方案
我会假设这self.doc_ids
是一个列表或其他可迭代的东西。
然后你应该可以使用这个:
res = pool.map(self.get_data_vector, self.doc_ids)
这意味着get_data_vector
将使用两个参数调用。第一个是self
, 作为绑定方法,第二个是 iterable 的元素self.doc_ids
。
推荐阅读
- jenkins - 我已经返回 jenkins 管道,它包含三台服务器,因此基于服务器选择部署应该继续
- python - 划分数据框 Python
- java - 从 Quarkus/Java 发送一个简单的 POST 请求
- python - 我有两个 pyspark 数据框,并想根据第一个数据框中的列值计算第二个数据框中的点数和
- android - Android Card View Shadow 在每一侧
- jmeter - 将变量打印到 CONSOLE
- google-cloud-platform - 最小实例 Google Cloud Run
- javascript - 绝对类型( import * as alias 语法不适用于 export = class)
- javascript - 更改数字 ro 字符串并正确舍入 JS
- ios - HealthKit -> 查询附有路线的锻炼