python - Using map() function with keyword arguments -
here loop trying use map
function on:
volume_ids = [1,2,3,4,5] ip = '172.12.13.122' volume_id in volume_ids: my_function(volume_id, ip=ip)
is there way can this? trivial if weren't ip
parameter, i'm not sure how deal that.
use functools.partial()
:
from functools import partial mapfunc = partial(my_function, ip=ip) map(mapfunc, volume_ids)
partial()
creates new callable, that'll apply arguments (including keyword arguments) wrapped function in addition whatever being passed new callable.
Comments
Post a Comment