Object Reference question

Simon Forman sajmikins at gmail.com
Fri Aug 21 10:23:30 EDT 2009


On Aug 21, 2:07 am, josef <jos... at gmail.com> wrote:
> To begin, I'm new with python. I've read a few discussions about
> object references and I think I understand them.
>
> To be clear, Python uses a "Pass By Object Reference" model.
> x = 1
> x becomes the object reference, while an object is created with the
> type 'int', value 1, and identifier (id(x)). Doing this with a class,
> x = myclass(), does the same thing, but with more or less object
> attributes. Every object has a type and an identifier (id()),
> according to the Python Language Reference for 2.6.2 section 3.1.
>
> x in both cases is the object reference. I would like to use the
> object to refer to the object reference. If I have a gross
> misunderstanding, please correct me.

x is not the object reference, it's just a string used as a key in a
dict (the value is the object reference):

|>>> globals()
|{'__builtins__': <module '__builtin__' (built-in)>, '__name__':
'__main__', '__doc__': None}
|>>> x = 1
|>>> globals()
|{'__builtins__': <module '__builtin__' (built-in)>, '__name__':
'__main__', '__doc__': None, 'x': 1}


I don't understand what you're trying to do, but give up the idea of
"object reference memory locations".  Any name binding in python just
associates a string with a object in one of various namespace
dictionaries.

HTH,
~Simon



More information about the Python-list mailing list