Python 清空类时出现空声明程序错误?
我正在尝试使用Cython编译以下Python 清空类时出现空声明程序错误?,python,compiler-construction,compiler-errors,cython,Python,Compiler Construction,Compiler Errors,Cython,我正在尝试使用Cython编译以下.pyx文件: import collections nil = object() # used to distinguish from None class TrieNode(object): __slots__ = ['char', 'output', 'fail', 'children'] def __init__(self, char): self.char = char self.output =
.pyx
文件:
import collections
nil = object() # used to distinguish from None
class TrieNode(object):
__slots__ = ['char', 'output', 'fail', 'children']
def __init__(self, char):
self.char = char
self.output = nil
self.fail = nil
self.children = {}
def __repr__(self):
if self.output is not nil:
return "<TrieNode '%s' '%s'>" % (self.char, self.output)
else:
return "<TrieNode '%s'>" % self.char
My setup.py当前看起来如下所示:
from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext
setup(
cmdclass = {'build_ext': build_ext},
ext_modules = [Extension("TrieNode", ["TrieNode.pyx"])]
)
我看到了一个例子,其中一个Python类被编译成一个Cython文件,没有问题,但这个类似乎不起作用。有人能告诉我我缺少什么吗?在
\uuuu init\uuu
方法中,有一个名为char
的变量。如果您将.py模块循环化,这是很好的。然而,在Cython.pyx文件中,即使是Pythondef
函数也可以有。我使用的是相同的版本:(你也在使用64位的机器吗?@eryksun:Rock star!我把char
改成\u char
,并且编译得很好。你能把这个作为一个答案发布出来,让我接受吗?
from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext
setup(
cmdclass = {'build_ext': build_ext},
ext_modules = [Extension("TrieNode", ["TrieNode.pyx"])]
)