[Python-Dev] Namespaces (original) (raw)

Aahz aahz@pythoncraft.com
Mon, 1 Apr 2002 13:56:57 -0500


On Mon, Apr 01, 2002, Martin v. Loewis wrote:

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

You're only correct if you define namespaces as being the set of nested first-level lookups. If you define "attribute" as "name bound to an object namespace", then we're pretty much in agreement. We certainly talk often enough of module namespaces; I think it makes sense to expand that usage to all objects.

It seems pretty clear to me that f.permissions does not live in the local/global/builtins namespace, but it sure lives in f's namespace. Because attributes are names like any other name and can be bound to any Python object, I think it lends crucial orthogonality to say that attributes live in object namespace.

Aahz (aahz@pythoncraft.com) <*> http://www.pythoncraft.com/

Why is this newsgroup different from all other newsgroups?