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

Michael Hoffman cam.ac.uk at mh391.invalid
Wed Jul 27 14:37:52 EDT 2005


Tito 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()

locals()["foo"]() will be a little more predictable than eval("foo()").
-- 
Michael Hoffman



More information about the Python-list mailing list