define a new func on the fly?

Donn Cave donn at u.washington.edu
Thu Mar 1 19:59:52 EST 2001


Quoth Bruce Edge <bedge at troikanetworks.com>:
| 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?


   >>> exec "def global_func_name():\n\tpass\n"
   >>> global_func_name
   <function global_func_name at 0x8000ca34>
   >>>

	Donn Cave, donn at u.washington.edu



More information about the Python-list mailing list