作者WhiteRiverX (WhiteRiverX)
看板Python
标题[问题] 如何把'list'变成'阵列'丢给C的函式?
时间Tue Feb 14 19:41:45 2012
大家好:
小弟最近想把用Python整理过的list(里面是float型态),
然後再把这个list丢给C的函式当引数。
两个文件像下面这样:
_______
test.c
=======
#include <stdio.h>
double CalcUSRsimilar (double *x1, double *x2, int nAtom)
{
int i;
for(i = 0; i < nAtom; i++)
{
printf("%f",*(x1+i) );
printf(" ");
}
double s;
s=1;
return s;
}
=====================================================================
_______
test.py
=======
import ctypes
USR_file = ctypes.cdll.LoadLibrary("./test.so")
USR = USR_file.CalcUSRsimilar
X=[1.2, 1.3]
Y=[2.2, 2.4]
print( USR( X, Y, 2 ) )
=====================================================================
也就是在Python里面宣告两个list,然後再丢给C显示出来。
test.c确定可以compile,问题卡在Python那关...
------------------------------------------------------------------------
Traceback (most recent call last):
File "./test.py", line 12, in <module>
print( USR( X, Y, 2 ) )
ctypes.ArgumentError: argument 1: <class 'TypeError'>: Don't know how to
convert parameter 1
------------------------------------------------------------------------
小弟google一阵子了,但网路上的文章大多比较难(好像都是举structure的例子...
但我应该不用用到那麽难吧!)。请各位大大务必提点小弟,感恩。
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.112.4.183
1F:推 suzuke:XD 02/14 19:59