An idiom for code generation with exec
bruno.42.desthuilliers at websiteburo.invalid
Mon Jun 23 12:15:07 CEST 2008
Maric Michaud a écrit :
> Le Monday 23 June 2008 09:22:29 Bruno Desthuilliers, vous avez écrit :
>>> 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.
>> I possibly messed up a couple things in the arguments, flags etc - I
>> very seldom use compile() and function(). The point was that it didn't
>> require any extra step.
> In the argument list of function type, the code object in first place is
> expected to be created directly (no exec - eval) with the python type 'code'
Which is what compile returns. But indeed, re-reading compile's doc more
carefully, I'm afraid that the code object it returns may not be usable
the way I thought. My bad. <OP>sorry</OP>
More information about the Python-list