id(...)内置函数的Python反函数

用户名

id内置函数有反函数还是反函数?我当时正在考虑使用它来编码和解码字符串,而不会花费太多时间或像PyCrypto一样有很多开销对我的需求很简单,因此我不想使用PyCrypto简单的编码和解码。

就像是:

>>> id("foobar")
4330174256
>>> reverse_id(4330174256) # some function like this to reverse.
"foobar"
维克多·卡斯蒂略·托雷斯(Victor Castillo Torres)

我不想从回答问题的个人那里窃取学分

This can be done easily by ctypes:

import ctypes
a = "hello world"
print ctypes.cast(id(a), ctypes.py_object).value
output:

hello world

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章