Re: [Beginner] Calling a function by its name in a string
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.python archive

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

From: Michael Hoffman <cam.ac.uk@mh391.invalid>
Date: Wed Jul 27 2005 - 20:37:52 CEST

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
Received on Thu Sep 29 17:11:48 2005