In this article, we will discuss how to get the value from the address in Python. First, we have to calculate the memory address of the variable or python object which can be done by using the id() function.
where, python_object is any python variable or data structure like list, tuple set, etc.
Now that we have addresses, we can get value/python objects again from the memory address using ctypes module.
ctypes stands for compatible data types, which allows calling functions in DLLs or shared libraries. It can be used to wrap these libraries in pure Python. It is used to get the value/Python objects using memory address
Actual value - [1, 2, 3, 4, 5]
Memory address - 140292824840224
Value - [1, 2, 3, 4, 5]
____________________________________
Actual value - (1, 2, 3, 4, 5)
Memory address - 140292853914128
Value - (1, 2, 3, 4, 5)
____________________________________
Actual value - {1, 2, 3, 4, 5}
Memory address - 140292824862304
Value - {1, 2, 3, 4, 5}
____________________________________
Actual value - {'id': 1, 'name': 'sravan kumar', 'address': 'kakumanu'}
Memory address - 140292825009760
Value - {'id': 1, 'name': 'sravan kumar', 'address': 'kakumanu'}
____________________________________