locals().update(...)

Steven D'Aprano steve+comp.lang.python at pearwood.info
Wed Jul 4 18:57:33 EDT 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.

http://docs.python.org/release/3.2/library/functions.html#globals

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


-- 
Steven



More information about the Python-list mailing list