【问题标题】:Py_InitModule and PyString_InternFromString in Python 3.5Python 3.5 中的 Py_InitModule 和 PyString_InternFromString
【发布时间】:2015-11-10 23:55:57
【问题描述】:

我想将我的 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 中的那些标识符等价于什么?

【问题讨论】:

标签: python python-3.x native-code


【解决方案1】:

对于Py_InitModule,您现在使用的是PyModule_Create。你可以看到example usage in the tutorial example on the Python docs page。

对于实习,Py3 的str 是基于Py2 的unicode 类型;在 C 层,您正在使用 PyUnicode 方法,例如PyUnicode_InternFromString。你仍然是 Python 级别的实习生 strs,但是实现类型已经改变了。

【讨论】:

    【解决方案2】:

    https://stackoverflow.com/a/28306354/320546 将帮助您处理Py_InitModule PyStr_InternFromString 是 Python 3 中的 PyString_InternFromString 等价物(参见 http://py3c.readthedocs.org/en/latest/reference.html#c.PyStr_InternFromString)

    【讨论】:

    • PyStr_InternFromString 来自第三方兼容性库,它不是任何东西的“Python 3 等价物”,它是一个调用函数的 Py2 或 Py3 版本的包装器,视情况而定。
    猜你喜欢
    • 2017-06-28
    • 2017-04-21
    • 1970-01-01
    • 2023-03-08
    • 2017-11-15
    • 1970-01-01
    • 1970-01-01
    • 2017-04-27
    • 1970-01-01
    相关资源
    最近更新 更多