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
--
[EMAIL PROTECTED] wrote:
hi
i have a dictionary defined as
execfunc = { 'key1' : func1 }
to call func1, i simply have to write execfunc[key1] .
No, you ALSO have to write ( ) [[parentheses]] after that. MENTIONING a
function doesn't call it, it's the parentheses that do it.
but if i
[EMAIL PROTECTED] 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
[EMAIL PROTECTED] writes:
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
Ron Adam wrote:
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...
Committed revision 41366.
You could then do...
func, args = execfunc['key1']
func(**args)
Interesting
Alex Martelli wrote:
execfunc = { 'key1' : (func1, ()),
'key2' : (func2, args) }
now, something like:
f, a = execfunc[k]
f(**a)
will work for either key.
Shouldn't func1's args be a dictionary, not a tuple?
--
http://mail.python.org/mailman/listinfo/python-list
Neal Norwitz wrote:
Ron Adam wrote:
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...
Committed revision 41366.
Committed revision 41366 ?
You could then do...
func, args =
Leif K-Brooks [EMAIL PROTECTED] wrote:
Alex Martelli wrote:
execfunc = { 'key1' : (func1, ()),
'key2' : (func2, args) }
now, something like:
f, a = execfunc[k]
f(**a)
will work for either key.
Shouldn't func1's args be a dictionary, not a tuple?
Yes,
On 1 Nov 2005 20:02:41 -0800, [EMAIL PROTECTED]
[EMAIL PROTECTED] wrote:
hi
i have a dictionary defined as
execfunc = { 'key1' : func1 }
##
def __HELLO(x=' '):
print 'HELLO',x
def __BYE(x=' '):
print 'BYE',x
def __PRINT(x=None, y=None):
print 'PRINT',x,y
cmds =