【问题标题】:Python - Convert PyInt into C intPython - 将 PyInt 转换为 C int
【发布时间】:2018-12-05 13:09:24
【问题描述】:

我目前在尝试检索我的 python 代码返回的值时遇到问题。

我的代码草稿是:

# I call a function that returns a PyObject
PyObject* pyObj_val = call_binding(...);

# This PyObject seems to be a PyInt as PyInt_Check returns 1
assert(PyInt_Check(pyObj_val) == 1);

# Now the only way i found to convert this PyInt to a [C] int is:
int my_val = (int) PyInt_AsLong(pyObj_val);

我想有一种方法可以在不经过长时间转换和 int 转换的情况下执行此操作。有人知道吗?

感谢您考虑我的请求。

【问题讨论】:

    标签: python c python-c-api


    【解决方案1】:

    简单地说:不,就是这样。没有单独的PyInt_AsInt 函数。

    【讨论】:

    • 好,那我就这样下去。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-12-28
    • 2011-12-21
    • 2013-04-18
    • 2021-04-27
    • 1970-01-01
    • 1970-01-01
    • 2023-03-29
    相关资源
    最近更新 更多