我开始尝试 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'
任何想法为什么会发生这种情况?
繁星点点滴滴
相关分类