用打印函数参数编译cython错误

moh*_*mad 14 cython python-3.x

当使用cython从helloworld.pyx创建helloworld.c时,发生此错误:

    error compiling Cython file:
------------------------------------------------------------
...
print('hello world',end='')
                      ^
------------------------------------------------------------

p21.pyx:1:23: Expected ')', found '='
Run Code Online (Sandbox Code Playgroud)

我创建helloworld.c的命令是:

cython3 --embed p21.pyx
Run Code Online (Sandbox Code Playgroud)

uzu*_*aki 11

看起来cython默认将所有打印视为python 2语句.要使用python 3打印功能,您需要从以后的模块导入它:

from __future__ import print_function

print('hello world',end='')
Run Code Online (Sandbox Code Playgroud)


Aki*_*oss 7

我不知道这是否仍然相关,但在我的情况下,使用 cython 0.23,要编译 Python3 代码,您必须传递 flag -3。例如

cython -3 mycode.py
Run Code Online (Sandbox Code Playgroud)