在cython中声明带有参数的函数时出错 < >在C++中找到了一个使用Python函数的方法,我遇到了Python,我正在编写一个简单的斐波那契函数,它把n个数字从一个特定的索引添加到给定的列表L中。我是cython的新手,所以错误可能很小:)。请指出问题所在: 从libcpp.list cimport列表 从测试导入测试和 cdef public long long gen_fibonacci(list[int] &l,int in,int n): num = 3 t1 = 0 t2 = 1 nextTerm = 0 i=1 if ind==1: l.append(0) l.append(1) i=3 if ind==2: l.append(1) i=2 while i<n: nextTerm=t1+t2 t1=t2 t2=nextTerm if num>=ind: i=i+1 l.append(nextTerm) num=num+1 return test_sum(l)

在cython中声明带有参数的函数时出错 < >在C++中找到了一个使用Python函数的方法,我遇到了Python,我正在编写一个简单的斐波那契函数,它把n个数字从一个特定的索引添加到给定的列表L中。我是cython的新手,所以错误可能很小:)。请指出问题所在: 从libcpp.list cimport列表 从测试导入测试和 cdef public long long gen_fibonacci(list[int] &l,int in,int n): num = 3 t1 = 0 t2 = 1 nextTerm = 0 i=1 if ind==1: l.append(0) l.append(1) i=3 if ind==2: l.append(1) i=2 while i<n: nextTerm=t1+t2 t1=t2 t2=nextTerm if num>=ind: i=i+1 l.append(nextTerm) num=num+1 return test_sum(l),python,c++,function,cython,Python,C++,Function,Cython,编译命令: cython -2 strat_plugin.pyx 尝试将中的更改为行中的另一个单词: cdef公共long long gen_fibonacci(list[int]&l,int-in,int-n):` 我想你应该用“in”而不是“ind”。此外,“In”是一个保留的关键字 cdef公共长长根fibonacci(列表[int]&l,int-ind,int-n): num=3 中的是一个Python关键字。选择另一个名称。酷,谢谢,错误消息有点没用 cython -2 strat_

编译命令:

cython -2 strat_plugin.pyx

尝试将中的
更改为行中的另一个单词:

cdef公共long long gen_fibonacci(list[int]&l,int-in,int-n):`

我想你应该用“in”而不是“ind”。此外,“In”是一个保留的关键字

cdef公共长长根fibonacci(列表[int]&l,int-ind,int-n):
num=3

中的
是一个Python关键字。选择另一个名称。酷,谢谢,错误消息有点没用
cython -2 strat_plugin.pyx