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: Bill Mill <bill.mill@gmail.com>
Date: Wed Jul 27 2005 - 20:18:25 CEST

On 7/27/05, Tito <titogarcia_borra_esto@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
Received on Thu Sep 29 17:11:46 2005