Asymmetry in globals __getitem__/__setitem__

Marko Rauhamaa marko at pacujo.net
Fri Jun 13 02:07:45 EDT 2014


Gregory Ewing <greg.ewing at canterbury.ac.nz>:

> I didn't think that using a custom mapping object for globals was
> officially supported. Has that changed?

The documentation is a bit vague about it:

   If only globals is provided, it must be a dictionary, which will be
   used for both the global and the local variables. If globals and
   locals are given, they are used for the global and local variables,
   respectively. If provided, locals can be any mapping object.

Now, if you define:

   class Namespace(dict):
       ...

A Namespace *is* a dict[ionary] in the classic OOP sense.


Marko



More information about the Python-list mailing list