Opposite of repr() (kind of)
TimeHorse
TimeHorse at gmail.com
Mon Apr 21 07:37:09 EDT 2008
On Apr 21, 7:05 am, Guillermo <guillermo.lis... at googlemail.com> wrote:
> Hi there,
>
> How can I turn a string into a callable object/function?
>
> 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. :)
>
> Regards,
>
> Guillermo
What version of Python are you using? I just tried
"callable(eval('len'))" on Python 2.5.1 and got True, and eval('len')
returns <built-in function len>.
More information about the Python-list
mailing list