2014-11-20 74 views
2

這是我試圖在python中構建包裝的代碼。ctypes <type'exceptions.TypeError'>

這是total.py文件(* C_T是長度爲7的空陣列(將內部函數來計算)中,t和Rh長度的Na陣列)

#double *initSeriesReversion(double *c_t, double *t, double *rh, int Na) 
_inSR = _modi.initSeriesReversion 
_inSR.argtypes = [ndpointer(ctypes.c_double * 7, flags="C_CONTIGUOUS"),ndpointer(ctypes.c_double * 100, flags="C_CONTIGUOUS"),ndpointer(ctypes.c_double * 100, flags="C_CONTIGUOUS"),ctypes.c_int] 
_inSR.restype = ctypes.POINTER(ctypes.c_double * 7) 

和蟒機能的研究

def ini_SR(t, rh, Na): 
    c_time = ctypes.POINTER(ctypes.c_double * 7) 
    c_freq = _inSR(c_time,t,rh,Na) 
    return c_time.value, c_freq 

錯誤: 文件 「」,第1行,在

File "total.py", line 28, in ini_SR 

c_time = ctypes.POINTER(ctypes.c_double * 7) 
ctypes.ArgumentError: argument 1: <type 'exceptions.TypeError'>: expected LP_c_double instance instead of _ctypes.PyCPointerType 

回答

2

c_time = ctypes.POINTER(ctypes.c_double * 7) 

聲明一個類型。您需要將類型的實例傳遞給C函數調用,而不是類型本身。

嘗試用

c_time_type = ctypes.POINTER(ctypes.c_double * 7) 
c_time = c_time_type() 

替換這一行(你可以寫c_time = ctypes.POINTER(ctypes.c_double * 7)()代替 - 注意,最終額外的括號 - 但我覺得不太清楚閱讀)