Using map() function with keyword arguments

前端 未结 5 1192
心在旅途
心在旅途 2020-11-28 06:29

Here is the loop I am trying to use the map function on:

volume_ids = [1,2,3,4,5]
ip = \'172.12.13.122\'
for volume_id in volume_ids:
    my_fun         


        
5条回答
  •  星月不相逢
    2020-11-28 07:12

    Use functools.partial():

    from functools import partial
    
    mapfunc = partial(my_function, ip=ip)
    map(mapfunc, volume_ids)
    

    partial() creates a new callable, that'll apply any arguments (including keyword arguments) to the wrapped function in addition to whatever is being passed to that new callable.

提交回复
热议问题