Python Using List/Multiple Arguments in Pool Map

前端 未结 3 1641
清酒与你
清酒与你 2021-02-20 14:13

I am trying to pass a list as a parameter to the pool.map(co_refresh, input_list). However, pool.map didn\'t trigger the function co_refresh

3条回答
  •  星月不相逢
    2021-02-20 14:33

    georgexsh's answer works perfectly in Python 3; the key is that starmap allows to pass multiple arguments into the function.

    However, if you use Python 2, you will need to use python classical unpacking mentioned in comments by Ahmed under the question here.

    In my case, I just need to "enlist" the argument first in the function.

    def func(args)
       (a, b, c, d) = args
       # You can then use a, b, c, d in your function
        return;
    

提交回复
热议问题