0

Is there a way to delete the memory address of a variable in python? For example, I was implementing an code like

var = 23 address = hex(id(var)) print (var+":"+address) del address print (var+":"+address) If I want to remove address of the variable var then show an error message like Name Error: name 'address' is not defined Is there any way to delete the variable address or modify the value of the variable using address variable?

hasnat ali
  • 11
  • 3

1 Answers1

0

When you're writing del adress you're not removing the adress of the variable, you're only clearing the "adress" variable which contains a string that represents the hexadecimal of the adress, that's why you're getting an "not defined" error.

You can access the value by using the ctypes module :

ctypes.cast(id(var), ctypes.py_object).value

But I don't know if it's possible to modify the variable, but like Chaos said : Basically, if you're trying to do this, you probably need to do something differently.

Kays Kadhi
  • 538
  • 6
  • 21