Modifying Class Object

Alf P. Steinbach alfps at start.no
Sat Feb 13 11:08:11 EST 2010


* Aahz:
> In article <mailman.2323.1265836683.28905.python-list at python.org>,
> Steve Holden  <steve at holdenweb.com> wrote:
>> Whether in CPython, Jython or IronPython the value returned by calling
>> id(x) (whether x is a literal, a simple name or a more complex
>> expression) is absolutely no use as an accessor: it does not give you
>> access to the referenced value.
>>
>> If you disagree, please write (in any implementation you like: it need
>> not even be portable, though I can't imagine why ti wouldn't be) a
>> Python function which takes an id() value as its argument and returns
>> the value for which the id() value was provided.
> 
> IIRC, I've seen ctypes code that uses id() to get access to the object,

Dino Viehland gave this code:

<quote author="Dino Viehland">
Just for fun this works in IronPython 2.6:

 >>> >>> import clr
 >>> >>> clr.AddReference('Microsoft.Dynamic')
 >>> >>> from Microsoft.Scripting.Runtime import IdDispenser
 >>> >>> x = object()
 >>> >>> id(x)
43
 >>> >>> IdDispenser.GetObject(43)
<object object at 0x000000000000002B>
 >>> >>> IdDispenser.GetObject(43) is x
True
</quote>



> but (obviously) I don't think that invalidates your point[er].

For my part I didn't think the above would be possible without enumerating all 
objects. I'm guessing that Steve didn't think so either. However, I seriously 
doubt that an agreement with my earlier statements of that was his point, 
considering the "if" above, which seems to imply to the reader that instead I'd 
argued what he's challenging.

Perhaps Steve was just confused.

My original statement, with reference to the Java language spec, didn't say much 
more about the language than that it has assignable references.

It took a long time to get the wild horses reined in in that direction.

But then two others ended up arguing that Python does not have references, with 
one of them maintaining that "refers to" in the language spec does not mean 
"refers to", but instead means "refers to", so I'm guessing it's religious, yes?


Cheers,

- Alf



More information about the Python-list mailing list