在c/c++中,通过&获取变量的内存地址,通过*获取内存地址中的数据。

在python中,通过id获取变量的内存地址,那如何通过内存地址获取数据呢?

import ctypes

value = 'hello world'  # 定义一个字符串变量
address = id(value)  # 获取value的地址,赋给address
get_value = ctypes.cast(address, ctypes.py_object).value  # 读取地址中的变量
print(address,get_value)
2390895579248 hello world

相关文章:

  • 2022-12-23
  • 2021-07-18
  • 2022-12-23
  • 2021-07-08
  • 2021-07-03
  • 2022-02-25
  • 2022-02-02
  • 2021-11-03
猜你喜欢
  • 2021-06-03
  • 2022-12-23
  • 2022-12-23
  • 2021-06-03
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案