on "Namespaces"
Steven D'Aprano
steven at REMOVE.THIS.cybersource.com.au
Tue Nov 10 00:02:25 EST 2009
On Sun, 08 Nov 2009 13:20:23 -0800, webtourist wrote:
> New bie Question:
> in "Zen of Python" - what exactly does the last one mean ? - Namespaces
> are one honking great idea -- let's do more of those!
>
> I mean why the emphasis ? Is it like saying "put modules into packages"
> in other programming paradigm s ?
Modules are namespaces. So are packages.
Classes and class instances are namespaces.
Even function scopes are namespaces. When you write:
n = None
def spam(n):
print "spam" * n
def ham(n):
print "ham" * n
the n inside spam() and ham() and the global n are in different
namespaces, and so independent.
http://en.wikipedia.org/wiki/Namespace
http://docs.python.org/tutorial/classes.html#python-scopes-and-namespaces
--
Steven
More information about the Python-list
mailing list