python - python 错误的 cython 包装器中的 AttributeError

标签 python cython

我在 cython 中为 python 创建了一个 C++ 包装器。

C++ 类的方法名称为 makeBooleanValue,但在 python 中我希望等效方法为 make_boolean_value。

但我收到错误:

Traceback (most recent call last): File "saxon_example.py", line 7, in xdmAtomicval = proc.make_boolean_value(False) AttributeError: 'saxonc.PySaxonProcessor' object has no attribute 'make_boolean_value'

我似乎无法在 cython 中使用不同的命名约定。

在 pxd 文件中,我有以下内容:

XdmAtomicValue * makeBooleanValue(bool b)

在 pyx 文件中,我有以下内容:

def make_boolean_value(self, b):
    cdef bool c_b = b
    cdef PyXdmAtomicValue val = PyXdmAtomicValue()
    val.derivedaptr = val.derivedptr = val.thisvptr = self.thisptr.makeBooleanValue(c_b)
    return val

但是在我的 python 示例脚本中:

print(dir(library))

我得到 make makeBooleanValue

请问我缺少什么想法吗?

最佳答案

当我运行 python 脚本时,pyx 文件中的更改似乎没有被拾取。但是当我从命令行运行 python 时它就会被拾取

关于python - python 错误的 cython 包装器中的 AttributeError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56237163/

相关文章:

python - Python 中是否有用于纯文本文件的 native 模板系统?

python - 15 秒空闲延迟加载 Windows 原生 Python 模块

python - 如何在 Cython 模块中将 #defined C 值暴露给 Python?

python - 如何使用 Python 访问属于对象的动态 C++ 数组变量?

c - 使用 cython_gsl 进行集成(加上将 numpy.array 寻址到 cython)

Python:跟踪列表中移动的元素

Python 2.7 : Print to File

python - 将多列转换为一行 (Pandas/Numpy)

python - 在 Cython 中调用点积和线性代数运算?

python - 使用 Python Nmap 在网络中连接移动信息