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

use*_*703 6 python uuid built-in

id内置函数是反向还是反向?我正在考虑使用它来编码和解码字符串,而不需要花费太多时间或像PyCrypto库那样有很多开销.对我的需求非常简单,所以我不想PyCrypto用于简单的编码和解码.

就像是:

>>> id("foobar")
4330174256
>>> reverse_id(4330174256) # some function like this to reverse.
"foobar"
Run Code Online (Sandbox Code Playgroud)

Vic*_*res 10

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

This can be done easily by ctypes:

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

hello world
Run Code Online (Sandbox Code Playgroud)