[Tutor] How do you execute a stored function?
Don Arnold
darnold02 at sprynet.com
Mon Aug 25 06:44:35 EDT 2003
----- Original Message -----
From: "Bruce Williams" <midnightcoder at comcast.net>
To: <tutor at python.org>
Sent: Monday, August 25, 2003 8:00 AM
Subject: [Tutor] How do you execute a stored function?
> I new to Python and am looking for something like the Lisp "eval"
function.
> I have had no trouble storing functions in a dictionary, but haven't
> stumbled upon a way to use them.
I don't know Lisp's "eval", but once you have the functions in a dictionary,
just access them with the appropriate key and call them like any other
function:
def func1(args=None):
print 'func1 called with:', args
def func2(args=None):
print 'func2 called with:', args
def func3(args=None):
print 'func1 called with:', args
funcDict = {1: func1, 2: func2, 3: func3}
funcDict[1](20)
>>> func1 called with: 20
funcDict[2]('test')
>>> func2 called with: test
funcDict[3]()
>>> func1 called with: None
> Regards,
> Bruce Williams
HTH,
Don
More information about the Tutor
mailing list