Opposite of repr() (kind of)

Bruno Desthuilliers bruno.42.desthuilliers at websiteburo.invalid
Mon Apr 21 13:26:24 CEST 2008


Guillermo a écrit :
> Hi there,
> 
> How can I turn a string into a callable object/function?

Depends on what's in your string.

> I have a = 'len', and I want to do: if callable(eval(a)): print
> "callable", but that doesn't quite work the way I want. :)

Works here:
Python 2.5.1 (r251:54863, May  2 2007, 16:56:35)
[GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
 >>> a = "len"
 >>> callable(eval(a))
True
 >>>




More information about the Python-list mailing list