define a new func on the fly?
Gregory Jorgensen
gregj at pobox.com
Thu Mar 1 19:49:24 EST 2001
eval() evaluates an expression. exec() executes a statement. Try this:
>>> exec("def f():\n\treturn 'hello'\t")
>>> f()
'hello'
>>> eval("f()")
'hello'
In article <3A9EE927.8744154E at troikanetworks.com>, Bruce Edge says...
>
>I'm trying to define a new function on the at runtime,
>
>this fails:
>
>>>> eval( "def global_func_name():\n\tpass" )
>Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> File "<string>", line 1
> def global_func_name():
> ^
>SyntaxError: invalid syntax
>
>any idea how I can do this?
>
>
>
>Thanks, Bruce.
Greg Jorgensen
Deschooling Society
Portland, Oregon, USA
gregj at pobox.com
More information about the Python-list
mailing list