Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cython error compiling with print function parameters

when use cython to create helloworld.c from helloworld.pyx , this error occured:

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

p21.pyx:1:23: Expected ')', found '='

my command to create helloworld.c is:

cython3 --embed p21.pyx
like image 254
mohammad Avatar asked Oct 04 '13 15:10

mohammad


2 Answers

Cython is defaulting to Python 2 semantics. Set the language level to 3, which can be done with the following comment:

#cython: language_level=3

ref: https://cython.readthedocs.io/en/stable/src/reference/compilation.html#compiler-directives

like image 136
YangZi Avatar answered Sep 21 '22 01:09

YangZi


It looks like cython treats all prints as python 2 statements by default. In order to use the python 3 print function you need to import it from the future module:

from __future__ import print_function

print('hello world',end='')
like image 20
uzumaki Avatar answered Sep 20 '22 01:09

uzumaki