Object Reference question

Bruno Desthuilliers bruno.42.desthuilliers at websiteburo.invalid
Fri Aug 21 10:34:09 CEST 2009


josef a écrit :
> 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. 

Nope. It's *a* reference to the object - or, more exactly, a key in a 
mapping (the current namespace), which is associatied with a reference 
to the object. You can translate:

    x = 1

to:

   current_namespace['x'] = int(1)


> I would like to use the
> object to refer to the object reference. If I have a gross
> misunderstanding, please correct me.
> 
> The following is what I would like to do:
> I have a list of class instances dk = [ a, b, c, d ], where a, b, c, d
> is an object reference. Entering dk gives me the object: [MyClass0
> instance at 0x0000, MyClass1 instance at 0x0008, MyClass2 instance at
> 0x0010 ... ]
> 
> I need the object reference name (a,b,c,d) from dk to use as input for
> a file.

???

Could you elaborate, please ?

>  Where do I find the memory location of the object reference
> and the object reference name memory location? 

short answer : you don't. Python is a high level language, 'memory 
location' is an implementation detail (and highly 
implementation-dependant), and *not* exposed (at least not in any usable 
way).

> I am unconcerned with
> the fact that the memory location will change the next time I run a
> python session. I will be using the object reference name for
> processing right away.
> 
> My main focus of this post is: "How do I find and use object reference
> memory locations?"
> 
> Thoughts?

Yes : please explain the problem you're trying to solve. I mean, the 
*real* problem - what you want to achieve -, not what you think is the 
solution !-)



More information about the Python-list mailing list