on "Namespaces"

W

webtourist

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 ?

thanks
 
S

Steven D'Aprano

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,608
Members
45,241
Latest member
Lisa1997

Latest Threads

Top