An idiom for code generation with exec

eliben eliben at
Sat Jun 21 08:10:16 CEST 2008

>    d = {}
>  execcode in globals(), d
>   return d['foo']
> My way:
>   return function(compile(code, '<string>', 'exec'), globals())

With some help from the guys at IRC I came to realize your way doesn't
do the same. It creates a function that, when called, creates 'foo' on
globals(). This is not exactly what I need.


More information about the Python-list mailing list