Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Python – Change value at memory address

For example, I have a variable called a, and need to change it by its memory address:

a: str = "hello"
address: int = id(a)

change_by_address(address, a, 'newval') # is something like this possible?

Is there some way to do this, perhaps in the ctypes library?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Absolutely, positively not. That ID is an address of SOMETHING in memory, but in C terms these are all moderately complicated data structures.

Python is not C. You cannot think of things in the same way.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading