[Beginner] Calling a function by its name in a string

Bill Mill bill.mill at gmail.com
Wed Jul 27 14:18:25 EDT 2005


On 7/27/05, Tito <titogarcia_borra_esto at gmail.com> wrote:
> Hi all:
> 
> Is there a metalanguage capability in Python (I know there are many) to
> call a function having its name in a string?
> 
> Something like:
> __call__("foo")
> 
> instead of:
> foo()
> 

>>> def foo(): print "foobarred"
...
>>> foo()
foobarred
>>> eval("foo()")
foobarred
>>>

Peace
Bill Mill
bill.mill at gmail.com



More information about the Python-list mailing list