[Python-Dev] PEP 338 - Executing Modules as Scripts
Nick Coghlan
ncoghlan at gmail.com
Sat Feb 11 14:59:40 CET 2006
Nick Coghlan wrote:
> The PEP now uses runpy for the module name, and run_module for the function
> used to locate and execute scripts. There's probably some discussion to be had
> in relation to the Design Decisions section of the PEP, relating to the way I
> wrote the module (the handling of locals dictionaries in particular deserves
> consideration).
Huh. Speaking of not-thoroughly-tested, exec + function code objects doesn't
seem to work anything like I expected, so some of my assumptions in the PEP
relating to the way the locals dictionary should be handled are clearly wrong.
As I discovered, the name binding operations in a function code object have no
effect whatsoever on the dictionaries passed to an invocation of exec.
I'll update the PEP to drop run_function_code, and make run_code a simple
wrapper around the exec statement that always returns the dictionary used as
'locals' (which may happen to be the same dictionary used as 'globals').
If the way exec handles function code objects and provision of a locals
dictionary ever changes, then run_code will pick up the new semantics
automatically.
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
---------------------------------------------------------------
http://www.boredomandlaziness.org
More information about the Python-Dev
mailing list