[Tutor] Notes on namespaces, scopes, etc

Kent Johnson kent37 at tds.net
Thu Aug 3 13:09:25 CEST 2006

Dave Kuhlman wrote:
> I believe that I've incorporated most, if not all, of the
> suggestions from those on the list, except for Danny's suggestion
> (above) about closures.
> The document itself is still here:
>     http://www.rexx.com/~dkuhlman/python_comments.html#namespaces

Very nice. Just a few notes:

- When you talk about the hierarchy of namespace lookup, you might just 
mention nested scopes and refer to the PEP for more info, instead of 
omitting it completely.

- In the section "Accessing namespace dictionaries" you write, "Note 
that for lexically/statically nested scopes (for example, a function 
defined inside a function), it seems that globals() and locals() still 
give access to all items in the accessible namespaces, /but/ do not give 
dictionary style access to all visible scopes." globals() and locals() 
give access to items in the global and local namespaces, not all 
accessible namespaces. As was noted in the emails, variables in nested 
scopes are not included in locals() and globals(). I think that's what 
you're trying to say but it isn't clear.

- PEP 227 is definitely the present, not the future. Nested scopes have 
been available since Python 2.1.


More information about the Tutor mailing list