Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在下面的代码中,如何使用纯 python 语法来注释self.acython 中的类型?
self.a
class C: def __init__(self): self.a = 1 @cython.locals(x = int) def f(self, x): self.a += x
以下适用于我,适用于 Cython 0.16 和 0.19.1
import cython @cython.cclass class C(object): a=cython.declare(cython.int) def __init__(self): self.a = 1 @cython.locals(x = int) def f(self, x): self.a += x def val(self): return self.a
如您所见cython.declare,应该在类中使用而不是在__init__.
cython.declare
__init__