how can I execute a function string
premshree_python at yahoo.co.in
Tue Jan 13 12:38:14 CET 2004
You need to use eval() to run code on-the-fly. See
--- Rajarshi Guha <rajarshi at presidency.com> wrote: >
> I have some code that generates a function on the
> fly in a string.
> At a later point in time I want to execute this
> function (which also
> requires a parameters to be passed to it). So the
> code is something like
> def generate_func():
> s = """ def function(x):
> print x
> return 2
> return s
> funcstring = generate_func()
> retval = ....
> That is, retval should have the value returned from
> the evaluation of the
> function in the string funcstring.
> Is this possible by means of simple function calls
> or does this involve
> some sort of black magic?
Yahoo! India Mobile: Download the latest polyphonic ringtones.
Go to http://in.mobile.yahoo.com
More information about the Python-list