Turning Strings into Functions

Terry Reedy tjreedy at udel.edu
Fri Sep 26 06:49:38 CEST 2003


"Freddy" <freddycooper01 at yahoo.com> wrote in message
news:46610d4e.0309251516.45a8eb01 at posting.google.com...
> How do you turn a string into a callable function?

If functions are defined as module scope, as is usual, an example:

>>> def f(*args): print args
...
>>> globals()['f'](*(1,'a'))
(1, 'a')

Or you can define your own dict mapping names to functions.

Terry J. Reedy






More information about the Python-list mailing list