How to call a function using apply with keyword args?
Martin v. Löwis
loewis at informatik.hu-berlin.de
Thu Jun 13 03:50:32 EDT 2002
"Achim Domma" <achim.domma at syynx.de> writes:
> I have a function like this:
>
> def MyFkt(A,B,C): pass
>
> and some parameters from a config file:
>
> params = {'A':5,'B':8,'C':9}
>
> how can I call MyFkt with this parameters?
I recommend
MyFkt(**params)
> I tried apply(MyFkt,[],params)
If you want to use apply, it is
apply(MyFkt, (), params)
The arguments need to be a tuple.
Regards,
Martin
More information about the Python-list
mailing list