How to call a function using apply with keyword args?

Anoop P B anoop79 at myrealbox.com
Thu Jun 13 03:42:24 EDT 2002


hi Achim,

try this:

def MyFkt(A=0,B=0,C=0): pass
params = {'A':5,'B':8,'C':9}
MyFkt(params)

the reason behind the error is coz u can only pass a dictionary using 
'apply' for keyword arguments. and keyword args are of the form 
keyword=value (see docs)

~anoop

Achim Domma wrote:
> Hi,
> 
> 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 tried apply(MyFkt,[],params)
> but get this error:
> 
> TypeError: MyFkt() takes exactly 3 non-keyword arguments (0 given)
> 
> any idea?
> 
> greetings
> Achim
> 
> 







More information about the Python-list mailing list