[問題] 如何把'list'變成'陣列'丟給C的函式?
大家好:
小弟最近想把用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
推
02/14 19:59, , 1F
02/14 19:59, 1F
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 1 之 2 篇):
Python 近期熱門文章
PTT數位生活區 即時熱門文章