我开始尝试使用Cython并遇到了以下问题。考虑以下代表3D空间中顶点的类:
#Vertex.pyx
cdef class Vertex(object):
cdef double x, y, z
def __init__(self, double x, double y, double z):
self.x = x
self.y = y
self.z = z
现在我尝试从Python控制台创建一个对象:
import Vertex as vt
v1 = vt.Vertex(0.0, 1.0, 0.0)
代码本身运行良好。但是,当我尝试访问类属性时,我会收到一个AttributeError
错误:
print v1.x
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-6-83d928d774b7> in <module>()
----> 1 print v1.x
AttributeError: 'Vertex.Vertex' object has no attribute 'x'
有什么原因导致这种情况发生?