我有一个带有以下签名的go库:
//export getData
func getData(symbol string, day int, month string, year int) string {
return "getData2"
}
在Python中,我喜欢下面的代码:
import ctypes
library = ctypes.cdll.LoadLibrary('./lib.so')
get_data = library.getData
# Make python convert its values to C representation.
get_data.argtypes = [ctypes.c_char_p, ctypes.c_int,ctypes.c_int,ctypes.c_int]
get_data.restype = ctypes.c_wchar
# j= get_data("BTC".encode('utf-8'), "3", "JAN".encode('utf-8'), "23".encode('utf-8'))
j= get_data(b"XYZ", 3, "JAN", 23)
print(j)
它给出了误差
ctypes.ArgumentError: argument 3: <class 'TypeError'>: wrong type
我使用的是Python 3.9
1条答案
按热度按时间j8ag8udp1#
在第4行,您使用了
get_data.argtypes = [ctypes.c_char_p, ctypes.c_int,ctypes.c_int,ctypes.c_int]
,但由于第3个参数是字符串,因此它应该是get_data.argtypes = [ctypes.c_char_p, ctypes.c_int,ctypes.c_char_p,ctypes.c_int]