How to call a function using apply with keyword args?
Benno
benjl at cse.unsw.edu.au
Thu Jun 13 07:35:27 EDT 2002
"Achim Domma" <achim.domma at syynx.de> wrote in message news:<ae9fud$u23$00$1 at news.t-online.com>...
> 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)
The code looks ok to me. This:
def pants(A, B, C):
print A, B, C
dikt = {"A":1,"B":2, "C":3}
# We can use 2.1 syntax to avoid calling apply
pants(**dikt)
# Or we can use apply if we want to.
apply(pants, [], dikt)
This works for me, so i'm not sure what you have missed.
Benno
More information about the Python-list
mailing list