Python id() does not return an address [was Re: why () is () and [] is [] work in other way?]
Chris Angelico
rosuav at gmail.com
Fri Apr 27 14:24:24 EDT 2012
On Sat, Apr 28, 2012 at 3:51 AM, Adam Skutt <askutt at gmail.com> wrote:
> Yes, there is a way. You add a function deref() to the language. In
> CPython, that simply treats the passed value as a memory address and
> treats it as an object, perhaps with an optional check. In Jython,
> it'd access a global table of numbers as keys with the corresponding
> objects as values, and return them. The value of id() is absolutely
> an address, even in Jython. The fact the values can move about is
> irrelevant.
Python already as dereferenceable addresses. Look.
def address(obj,table=[]):
for i,o in enumerate(table):
if obj is o: return i
table.append(obj)
return len(table)-1
def deref(addr):
return address.__defaults__[0][addr]
You can take the address of an object (interning it, effectively), and
later dereference it. Proves nothing.
ChrisA
More information about the Python-list
mailing list