reference vs. name space question

Ben Finney ben+python at benfinney.id.au
Sat Oct 9 17:36:37 EDT 2010


chad <cdalten at gmail.com> writes:

> >>> print one
> <__main__.foo instance at 0xb7f3a2ec>
> >>> print two
> <__main__.foo instance at 0xb7f3a16c>
> >>> one.x
> 1
>
>
> Is 'one' a reference or a name space?

Yes.

It's a reference to an instance of the ‘foo’ type.

That instance is also a namespace; in other words, its attributes are in
a distinct namespace from all other instances.

This is complicated by the fact that it *also* gives access to the
attributes of ‘foo’, shared by all instances of that type. But that's
part of what it means to be an instance of the ‘foo’ type.

> Also, in 'one.x'. would 'one' be the name space?

It's *a* namespace. Since ‘one.x’ also presumably has attributes, then
it, too, is a namespace.


Learn more about classes and namespaces in Python's documentation
<URL:http://docs.python.org/tutorial/classes.html>.

In fact, you should work through the entire tutorial from start to
finish, experimenting manually with each example until you unsderstand
before moving on. That will give you a very solid grounding in Python.

-- 
 \                “I got fired from my job the other day. They said my |
  `\          personality was weird. … That's okay, I have four more.” |
_o__)                                       —Bug-Eyed Earl, _Red Meat_ |
Ben Finney



More information about the Python-list mailing list