string to function reference

Warren Postma embed at
Fri Sep 1 16:42:37 CEST 2000

"Igor V. Rafienko" <igorr at> wrote in message
news:xjvem34ibkk.fsf at
> I've got a string holding a name of the function in the same module:
> def foo():
>     print "I'm foo"
> s = "foo"
> The question is, how do I call the function foo given its name
> All of these approaches are simply waay too ugly, imvho. Does anyone
> see a simpler/cleaner/more elegant way of achieving this.

quoth the buddha:
  It is not Python which is not elegant. It is your conception of Python
which is not elegant.

[ I was just re-reading "Zen and the Art of Motorcycle Maintenance" again
last night.  He made mention of a class of technical problems referred to by
radio-repairmen as a "short between the earphones".  Both funny, and
profound. ]


More information about the Python-list mailing list