Steven D'Aprano steve+comp.lang.python at pearwood.info
Thu Jul 5 00:57:33 CEST 2012

On Wed, 04 Jul 2012 18:48:08 -0400, Dave Angel wrote:

> As i said above, the rules are different for globals, and they are even
> if you use locals() to access them.  However, i'd consider it prudent
> never to assume you can write to the dictionary constructed by either
> the locals() or the globals() functions.

globals() is implicitly documented as being writable: "This is always the 
dictionary of the current module..." -- unless you have a module with a 
read-only dict, that is writable.


There are tricks to getting read-only namespaces, but you can 
legitimately expect to write to globals().


More information about the Python-list mailing list