Calling function keywords from a dictionary
Aloysio Figueiredo
xpythonist at yahoo.com.br
Fri Mar 26 08:05:30 EST 2004
>>> def myfunc(x,y,z, **kw):
... return x*x + y*y + z*z
...
>>> dic = {
... 'action' : 'myfunc',
... 'x' : 1,
... 'y' : 2,
... 'z' : 3
... }
>>> f = globals()[dic['action']]
>>> f(**dic)
14
HTH,
Aloysio
--- Alexander Straschil <e9526547 at stud3.tuwien.ac.at> escreveu:
> Hello!
>
> I'm fooling around with a class wich can map cgi-parameters to
> function named parameter.
>
> I have a dic like
> dic = {
> 'action': 'myfunc',
> 'x': 1,
> 'y': 2,
> 'z': 3
> }
> and I have a method
> def myfunc(x, y, z, a=None, b=None)
>
> What I want to do ist calling the method defined in 'action' with
> all the named parameter, also instead of
> self.myfunct(x=1, y=2, z=3)
> I want to do
> f = getattr(self, dic['action'])
> f(named parameter from the dic)
> Its a little like zope does it, but i didnt find it in the Zope
> Sources ;-)
> How can do that?
>
> Thanks, AXEL.
> --
> http://mail.python.org/mailman/listinfo/python-list
______________________________________________________________________
Yahoo! Mail - O melhor e-mail do Brasil! Abra sua conta agora:
http://br.yahoo.com/info/mail.html
More information about the Python-list
mailing list