Yux*_*ang 9 python const cython
我在这个链接中读到:https://github.com/cython/cython/wiki/FAQ#id35我的Cython 0.20.1应该能够支持const.
但是我的以下代码无法编译:
cdef const double a = 2.5
print(a)
Run Code Online (Sandbox Code Playgroud)
在编译期间,它说
test.pyx:5:5: Assignment to const 'a'
Traceback (most recent call last):
File "setup1.py", line 11, in <module>
ext_modules = cythonize(extensions)
File "X:\WinPython3\python-3.3.5.amd64\lib\site-packages\Cython\Build\Dependencies.py", line 785, in cythonize
cythonize_one(*args[1:])
File "X:\WinPython3\python-3.3.5.amd64\lib\site-packages\Cython\Build\Dependencies.py", line 902, in cythonize_one
raise CompileError(None, pyx_file)
Cython.Compiler.Errors.CompileError: test.pyx
Run Code Online (Sandbox Code Playgroud)
Fre*_*Foo 16
const 适用于函数参数,但不适用于此构造,因为Cython如何将其编译为C.
cdef double a = 2.5
Run Code Online (Sandbox Code Playgroud)
变
double __pyx_v_a;
/* lots of other declarations */
__pyx_v_a = 2.5;
Run Code Online (Sandbox Code Playgroud)
这不适用于const变量.实际上,你不能const在所有的地方使用Cython,你可以在C中使用它.
| 归档时间: |
|
| 查看次数: |
4157 次 |
| 最近记录: |