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

Peter Otten __peter__ at web.de
Mon Jan 23 14:34:06 EST 2017


Sourabh Kalal 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

Use ctypes:

$ python3
Python 3.4.3 (default, Nov 17 2016, 01:08:31) 
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ctypes
>>> ctypes.c_ubyte.from_address(id(10) + 24).value = 11
>>> 10 == 11
True

:)




More information about the Python-list mailing list