Is it possible to get the Physical memory address of a variable in python?

Skip Montanaro skip.montanaro at gmail.com
Mon Jan 23 14:05:58 EST 2017


On Mon, Jan 23, 2017 at 12:49 PM, Chris Angelico <rosuav at gmail.com> wrote:
>
> On Tue, Jan 24, 2017 at 4:49 AM, Sourabh Kalal <kalalsunnyy at gmail.com> wrote:
> > how we can access the value from using id..
> > like x=10
> > id(x)
> > 3235346364
> >
> > how i can read value 10 using id 3235346364
>
> No, you can't. That isn't a memory address - it's just a unique
> identifier. Python doesn't have memory addresses.

Well, it might be, but that would be very implementation-dependent.
Any attempt to treat an id as a memory address and interpret the
object at that address as the beginning of a PyObject of any kind will
be fragile in the extreme. Even if you have two different
implementations at hand which both use memory addresses as convenient
ids, there's no guarantee that the address represents that start of a
CPython PyObject.

>>> hex(3235346364)
'0xc0d777bc'

There. *Now* you have an address. Hack to your heart's content. <wink>

Skip


More information about the Python-list mailing list