id(...)内置函数的Python反函数 [英] Python inverse function of id(...) built-in function
本文介绍了id(...)内置函数的Python反函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
id
内置函数是否存在反函数?我当时正在考虑使用它来编码和解码字符串,而不会花费太多时间或像 PyCrypto
库那样有很多开销。对我的需求很简单,所以我不想使用 PyCrypto
进行简单的编码和解码。
Is there a reverse or inverse of the id
built-in function? I was thinking of using it to encode and decode string without taking too much time or having a lot of overhead like the PyCrypto
library. The need for me is quite simple so I don't want to use PyCrypto
for a simple encode and decode.
类似的东西:
>>> id("foobar")
4330174256
>>> reverse_id(4330174256) # some function like this to reverse.
"foobar"
推荐答案
我不想窃取回答问题的人的信用
This can be done easily by ctypes:
import ctypes
a = "hello world"
print ctypes.cast(id(a), ctypes.py_object).value
output:
hello world
这篇关于id(...)内置函数的Python反函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文