【发布时间】:2020-05-06 11:30:20
【问题描述】:
想出一种在 c++ 中使用 python 函数的方法,我遇到了 python,我正在编写一个简单的斐波那契函数,它将特定索引中的 n 个数字添加到给定的列表 l 中。我是 cython 的新手,所以错误可能是微不足道的:)。请指出有什么问题: 从 libcpp.list cimport 列表 从测试导入 test_sum
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)
错误:
cdef public long long gen_fibonacci(list[int] &l,int in,int n):
^
------------------------------------------------------------
strat_plugin.pyx:4:53: Expected ')', found 'in'
编译命令:
cython -2 strat_plugin.pyx
【问题讨论】:
-
in是 Python 关键字。选择另一个名字。 -
酷,谢谢,错误信息有点没用
标签: python c++ function cython