[Tutor] Alan Gauld's tut - namespaces
kent37 at tds.net
Thu Apr 27 12:19:55 CEST 2006
Alan Gauld wrote:
> However I'll refrain from saying much more since I do think the
> namespaces topic could be significantly improved if only I could
> find better words and examples.
Looking at the tutorial, I think it jumps too quickly to more advanced
material (multiple modules) before explaining the basics of how a name
is resolved within a single module. You list the different scopes but
you don't explain how they are searched for a name.
Once it is clear that names are searched in the *lexically* enclosing
module, it will make more sense that print42() prints the value of spam
It might help to talk about name binding explicitly - that importing a
module binds a name to the module, and importing a function from the
module binds a name to the function. This might help make the
distinction that importing doesn't include anything new in the importing
module, it just creates references to the imported module or its attributes.
You are missing a namespace, BTW. Since Python 2.1 the search order is
local, *enclosing*, global and builtin.
More information about the Tutor