[Tutor] Dynamic Function Calls
Megan Land
mland at us.ibm.com
Fri Aug 14 15:06:52 CEST 2009
All three methods are defined below the snippet I provided.
def func():
code...
def func0():
do stuff
def func1():
do stuff
def func2():
do stuff
Megan Land
FVT Blade EMET Test Engineer
mland at us.ibm.com
From: Kent Johnson <kent37 at tds.net>
To: Megan Land/Raleigh/Contr/IBM at IBMUS
Cc: tutor at python.org
Date: 08/13/2009 05:18 PM
Subject: Re: [Tutor] Dynamic Function Calls
Sent by: kent3737 at gmail.com
On Thu, Aug 13, 2009 at 3:30 PM, Megan Land<mland at us.ibm.com> wrote:
> Hi,
>
> I'm trying to call a function from a dictionary. I did some googling and
> from what I can tell my code should work, but doesn't. Here's an example:
>
> def myFunc(self, inputList):
> dict={0: func0, 1: func1, 2:func2}
> for element in inputList:
> dict[element]()
>
> When I go to run this I get an error saying func0 is not defined. Does
> anyone have any ideas as to why this won't work? I'm using Python 2.6 if
> that makes any difference.
You don't show any definition for func0 in the above snippet. Where is
it defined?
Kent
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090814/a9998943/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: graycol.gif
Type: image/gif
Size: 105 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/tutor/attachments/20090814/a9998943/attachment.gif>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ecblank.gif
Type: image/gif
Size: 45 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/tutor/attachments/20090814/a9998943/attachment-0001.gif>
More information about the Tutor
mailing list