Calling a function or method by name

Jonathan Gardner jgardn at alumni.washington.edu
Wed Jan 23 17:18:51 EST 2002


On Thursday 24 January 2002 01:14 am, Eric Brunel wrote:
> > I want to use a dict. The keys will be the value of the key being
> > pressed. The values will be the name of the function to call.
>
> Why don't you directly store the methods themselves instead of their names?
> Then, you'll just have to do:
> dict[key]()
>
>  - eric -

I could do this, but this would mean I have to first define the method, and 
then assemble the dictionary. While it is possible, it just doesn't look as 
neat and it is not as easy to read.

Jonathan




More information about the Python-list mailing list