dictionary that have functions with arguments
Ron Adam
rrr at ronadam.com
Tue Nov 1 23:25:32 EST 2005
s99999999s2003 at yahoo.com wrote:
> hi
> i have a dictionary defined as
>
> execfunc = { 'key1' : func1 }
>
> to call func1, i simply have to write execfunc[key1] .
> but if i have several arguments to func1 , like
>
> execfunc = { 'key1' : func1(**args) }
>
> how can i execute func1 with variable args?
> using eval or exec?
>
> thanks
Eval or exec aren't needed. Normally you would just do...
execfunc['key1'](**args)
If your arguments are stored ahead of time with your function...
execfunc = {'key1':(func1, args)}
You could then do...
func, args = execfunc['key1']
func(**args)
Cheers,
Ron
More information about the Python-list
mailing list