[Python-Dev] Namespaces
Martin v. Loewis
martin@v.loewis.de
01 Apr 2002 10:00:04 +0200
Aahz <aahz@pythoncraft.com> writes:
> Well, no. First-level names, yes, but each object itself is a
> namespace, so every name will be bound to an object that can contain
> names. To use my favorite example:
>
> def f():
> pass
>
> f.permissions = 'author'
Except that those are not names, they are attributes. Namespaces nest,
in Python; permissions does not live in namespace, which becomes
obvious if you try to nest it
def f():
return permissions
f.permissions = 'author'
print f()
Traceback (most recent call last):
File "a.py", line 5, in ?
print f()
File "a.py", line 2, in f
return permissions
NameError: global name 'permissions' is not defined
Regards,
Martin