Py_InitModule 和 PyString_InternFromString 在 Python 3.5

Py_InitModule and PyString_InternFromString in Python 3.5

我想将我的 Python 版本从 2.7 更新到 3.5。

编译使用 PyString_InternFromString 和此 Py_InitModule

的代码时

我收到错误消息:

Error   199 error C3861: 'Py_InitModule': identifier not found
Error   196 error C3861: 'PyString_InternFromString': identifier not found

我的问题是,python 3.5 中的那些标识符有什么等价物?

会帮助你 Py_InitModule PyStr_InternFromString 是 Python 3 等价于 PyString_InternFromString(参见 http://py3c.readthedocs.org/en/latest/reference.html#c.PyStr_InternFromString

对于 Py_InitModule,您现在使用的是 PyModule_Create. You can see example usage in the tutorial example on the Python docs page

对于实习,Py3的str是基于Py2的unicode类型;在 C 层,您正在使用 PyUnicode 方法,例如PyUnicode_InternFromString。您仍在实习 Python 级别 str,但实施类型已更改。