access address from object and vice versa

Chris Angelico rosuav at gmail.com
Sat Jan 21 23:55:19 EST 2012


On Sun, Jan 22, 2012 at 2:04 PM, Tamer Higazi <th982a at googlemail.com> wrote:
> Hi people!
> I have asked myself the following thing.
>
> How do I access the address of an object and later get the object from
> that address ?!

The problem with that sort of idea is that it mucks up garbage
collection. CPython, for example, maintains a reference count for
every object; your address is, in a sense, another reference, but one
that the GC doesn't know about - so it might release the object and
reuse the memory.

What you can do, though, is simply have another name bound to the same
object. You can then manipulate the object through that name, and
it'll function just like a pointer would in C. The original name and
the new name will function exactly the same.

ChrisA



More information about the Python-list mailing list