Returning a value from exec or a better solution
ethan at stoneleaf.us
Tue Aug 30 22:59:34 CEST 2011
Rob Williscroft wrote:
> Ethan Furman wrote in news:4E5D29C8.8010206 at stoneleaf.us in
>> Jack Trades wrote:
>>> On Tue, Aug 30, 2011 at 2:37 AM, Rob Williscroft wrote:
>>>> If an impementation (as you say up thread) can populate globals
>>>> or locals with whatever they want, then how do you know that last
>>>> item added was the function definition the user supplied ?
>> Because the implementation will add things before the exec is processed.
> How do you know this ?, it isn't what the docs say.
The docs don't say when, true -- so I don't know for sure that all
additions happen before the exec since I haven't delved into the source
Okay, just perused builtin_exec in bltinmodule.c, and I can say that
cPython (somewhere in 3.2-3.3 land) only adds __builtins__ if not
already there, and that it does it first.
Which makes sense -- after all, what's the point of adding stuff to
globals() *after* the code has been run?
More information about the Python-list