坐在蘑菇上,思考着为实现Python的名称破坏算法而添加一个函数的复杂之处时,一个非常好的主意出现在我的脑海中。为什么不使用已经用语言制作的食谱来实现这样的目标呢?所以我把ctypes从我的书包里拉出来,帮我完成了ctypes.pythonapi._Py_Mangle('Demo', '__test')。瞧,一个错误出现在空中说OSError: exception: access violation reading 0x00000A65646F00A8,并没有费心解释的难题更多。
与口译人员的充分互动如下:
Python 3.4.2 (v3.4.2:ab2c023a9432, Oct 6 2014, 22:16:31) [MSC v.1600 64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> import ctypes
>>> ctypes.pythonapi._Py_Mangle('Demo', '__test')
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
ctypes.pythonapi._Py_Mangle('Demo', '__test')
OSError: exception: access violation reading 0x00000A65646F00A8有人知道要成功调用mangling函数需要更改什么吗?
发布于 2015-01-13 17:42:31
由于eryksun的评论,这个问题的答案相当简单:
>>> from ctypes import pythonapi, py_object
>>> py_mangle = pythonapi._Py_Mangle
>>> py_mangle.argtypes = py_object, py_object
>>> py_mangle.restype = py_object
>>> py_mangle('Demo', '__test')
'_Demo__test'https://stackoverflow.com/questions/27926429
复制相似问题