[Python-Dev] Re: Re: PEP 267 improvement idea
Terry Reedy
tjreedy@udel.edu
Tue, 14 Jan 2003 13:44:37 -0500
> overhead pays when it's used as a namespace. Both
"lookdict_namespace"
> and "lookdict_string" will fall back to a "lookdict" dictionary when
a
> non-string key is inserted.
Until reading this sentence, I had never thought of doing something so
bizarre as adding a non-string key to a namespace (via the 'backdoor'
.__dict__ reference). But it currently works.
>>> import __main__
>>> __main__.__dict__[1]='x'
>>> dir()
[1, '__builtins__', '__doc__', '__main__', '__name__', 'x']
However, since the implementation of namespaces is an implementation
detail, and since I can (as yet) see no need for the above (except to
astound and amaze), I think you (and Guido) should feel free to
disallow this, especially if doing so facilitates speed improvements.
Terry J. Reedy