Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/jsf/5.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 调用具有pool.map的类中的函数,该类只有一个参数,self:TypeError:map()缺少1个必需的位置参数:';iterable';_Python_Threadpool - Fatal编程技术网

Python 调用具有pool.map的类中的函数,该类只有一个参数,self:TypeError:map()缺少1个必需的位置参数:';iterable';

Python 调用具有pool.map的类中的函数,该类只有一个参数,self:TypeError:map()缺少1个必需的位置参数:';iterable';,python,threadpool,Python,Threadpool,我试图用pool map从同一个类中的另一个函数调用一个类中的函数 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_id,它

我试图用pool map从同一个类中的另一个函数调用一个类中的函数

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_id,它是一个列表

我现在这样称呼它

res = pool.map(__class__.get_data_vector,(self,self.doc_ids))
def get_data_vector(self, doc_id):
这个函数应该这样调用

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\u id
是一个列表或其他可编辑的内容

那么您应该能够使用以下功能:

res = pool.map(self.get_data_vector, self.doc_ids)

这意味着将使用两个参数调用
get\u data\u vector
。第一个是
self
,作为一个绑定方法,第二个是iterable
self的元素。doc_id

map
需要两个参数:函数和iterable。@WillemVanOnsem但是如果函数只接收self,iterable在这里会是什么呢?那么
map
就不是这样了,
map
将一个iterable转换为一个新的iterable,它在每个元素上应用一个函数。如果不是map,还有其他选项来完成我想做的事情吗?那么你想做什么呢?