python數組指針
1. ptyhong璋冪敤DLL錛屾庝箞浣跨敤緇撴瀯浣撴暟緇勬寚閽堝仛鍙傛暟
ptyhong璋冪敤DLL錛屽備綍浣跨敤緇撴瀯浣鏁扮粍鎸囬拡鍋氬弬鏁
C++鍑芥暟鍘熷瀷
typedef struct
{
unsigned long DeviceType;
int Handle;
int NumberOfClients;
int SerialNumber;
int MaxAllowedClients;
}NeoDevice;
int _stdcall icsneoFindNeoDevices(unsigned long DeviceTypes, NeoDevice *pNeoDevices, int *pNumberOfDevices);
浣跨敤python濡備笅錛
class NeoDevice(Structure):
_fields_ = [("DeviceType",c_ulong),
("Handle",c_int),
("NumberOfClients",c_int),
("SerialNumber",c_int),
("MaxAllowedClients",c_int)]
class cNeoVICan(CCanBase):
def __init__(self):
neoVi = windll.icsneo40
self.icsneoFindNeoDevices = neoVi.icsneoFindNeoDevices
if __name__ == "__main__":
canBus = cNeoVICan()
print canBus.icsneoGetDLLVersion()
iNumberOfDevices = [NeoDevice() for x in range(10)]
num = c_int
iResult = canBus.icsneoFindNeoDevices(c_ulong(65535), pointer(iNumberOfDevices), byref(num))
浣嗘槸浼氭姤濡備笅閿欒錛
Traceback (most recent call last):
File "C:\Work\Project\GUI\wxPyCANC303\Drv\source\src\drv\neoVI\cNeoVICan.py", line 224, in <mole>
iResult = canBus.icsneoFindNeoDevices(c_ulong(65535), pointer(iNumberOfDevices), byref(num))
TypeError: _type_ must have storage info
璇烽棶鏄浠涔堥敊璇鍘熷洜鍟婏紵
璋㈣阿銆
------瑙e喅鏂規--------------------
鍥犱負python鐨刲ist涓嶆槸涓涓猚types綾誨瀷
姝g『鍋氭硶鏄
class NeoDevice(Structure):
_fields_ = [("DeviceType",c_ulong),
("Handle",c_int),
("NumberOfClients",c_int),
("SerialNumber",c_int),
("MaxAllowedClients",c_int)]
class cNeoVICan(CCanBase):
def __init__(self):
neoVi = windll.icsneo40
self.icsneoFindNeoDevices = neoVi.icsneoFindNeoDevices
if __name__ == "__main__":
canBus = cNeoVICan()
print canBus.icsneoGetDLLVersion()
iNumberOfDevices = (NeoDevice * 10)()
num = c_int()
iResult = canBus.icsneoFindNeoDevices(c_ulong(65535), cast(iNumberOfDevices, POINT(NeoDevice)), byref(num))
2. 編程語言Python和Java哪個簡單呀
編程語言Python和Java相比較而言,Python更簡單一點。以下內容會詳細介紹兩款編程語言。
總之,Python 和Java 都是功能很強大的編程語言,建議新手先從Python 開始學。
3. 璁$畻鏈鴻璦瀛︿範絎旇
鏈鏂囧皢涓哄ぇ瀹朵粙緇嶈$畻鏈鴻璦瀛︿範絎旇幫紝鍖呮嫭C璇璦銆丆錛岋紝銆丣AVA銆丳ython銆丄ccess銆丮ySQL銆乄eb銆丮S Office銆乄PS Office絳夊唴瀹廣
👨💻C璇璦
Dos鍛戒護銆佽$畻鏈虹粍鎴愬師鐞嗐佸氬獟浣撱佹暟鎹搴撴搷浣溿佽$畻鏈虹綉緇溿丆璇璦紼嬪簭璁捐°佷笂鏈鴻冭瘯銆
👨💻C++
C++璇璦姒傝堪銆丆++璇璦鏁版嵁綾誨瀷銆佽繍綆楃﹀拰琛ㄨ揪寮忋佸熀鏈鎺у埗璇鍙ャ佹暟緇勩佹寚閽堜笌寮曠敤銆佸嚱鏁般佺被鍜屽硅薄緇ф壙銆佹ā鏉跨瓑鍐呭廣
👨💻JAVA
JAVA璇璦姒傝恆丣AVA鏁版嵁綾誨瀷銆佽繍綆楃﹀拰琛ㄨ揪寮忋佹祦紼嬫帶鍒躲佺被銆佹暟緇勫拰瀛楃︿覆鎿嶄綔銆佸紓甯稿勭悊銆佽緭鍏ヨ緭鍑哄強鏂囦歡鎿嶄綔銆佺嚎紼嬩笌瀵硅薄涓茶屽寲銆佺紪鍐欏浘褰㈢敤鎴風晫闈銆丄PPLET紼嬪簭璁捐★細JZSDK鐨勪笅杞藉拰鎿嶄綔銆丣AVA鐨勫簲鐢ㄣ
👨💻Python
Python璇璦鍩烘湰璇娉曞厓緔犮佸熀鏈鏁版嵁綾誨瀷銆佺▼搴忕殑鎺у埗緇撴瀯銆佹枃浠跺拰鏁版嵁鏍煎紡鍖栥丳ython璁$畻鐢熸併
👨💻Access
鏁版嵁搴撶郴緇熴佹暟鎹搴撳拰琛ㄣ佹暟鎹搴撴煡璇㈢獥浣撱佹姤琛ㄣ佹暟鎹璁塊棶欏點佸畯銆佹ā鍧楃瓑銆
👨💻MySQL
鏁版嵁搴撳熀鏈姒傚康涓庢柟娉曘丮ySQL騫沖彴涓嬬殑SQL銆佷氦浜掓搷浣溿丮ySQL鐨勬暟鎹搴撶紪紼嬨丮ySQL鐨勭$悊涓庣淮鎶ゃ丮ySQL鐨勫簲鐢ㄧ紪紼嬬瓑銆
👨💻Web
Web鎶鏈鍩虹銆丠TTP鍗忚鍩虹銆丠TML鍩虹銆丆SS鍩虹銆丣avaScript紼嬪簭璁捐″熀紜銆佸姩鎬佺綉欏墊妧鏈姒傝堪銆
👨💻MS Office
璁$畻鏈虹殑鍩虹鐭ヨ瘑銆乄ord鐨勫姛鑳藉拰浣跨敤銆丒xcel鐨勫姛鑳藉拰浣跨敤銆丳owerPoint鐨勫姛鑳藉拰浣跨敤銆
👨💻WPS Office
鍚勪釜杞浠剁殑鍔熻兘鍜屼嬌鐢ㄣ
4. C++調用時python時,如何傳入數組做為參數
題主,你基本操作沒什麼問題,有幾個小地方要修改一下,修改如下:
你的源碼:
PyObject* list = PyList_New(3);
for (size_t i = 0; i < 3; i++)
PyList_Append(list, Py_BuildValue("i", i));
PyEval_CallObject(pFunc, list);
--------------------------------------------------------------------------------------
修改後,應該是這樣
PyObject*pArgs=NULL;
PyObject*list=PyList_New(0);//3改成0
pArgs=PyTuple_New(1);//定義1個參數
for(size_ti=0;i<3;i++)
PyList_Append(list,Py_BuildValue("i",i));//這樣才能用Append,
PyTuple_SetItem(pArgs,0,list);//將列表賦給參數
PyEval_CallObject(pFunc,list);//傳入參數,調用函數
注意事項:PyList_New(0)初始化0的時候,應該用Append初始化
PyList_New(3)初始化3個時候,應該用SetItem初始化
如果用Append的話,會出現[NULL,NULL,NULL]的情況
我在給一個完整的:
Python :(hello.py)
defTestList(nlist):
print(nlist)
return
一般參數都是已元組形式傳入的
Py_Initialize();
PyRun_SimpleString("importsys");
PyRun_SimpleString("sys.path.append('./')");
PyObject*pMole=NULL;
PyObject*pList=NULL;
PyObject*pFunc=NULL;
PyObject*pArgs=NULL;
pMole=PyImport_ImportMole("hello");
pFunc=PyObject_GetAttrString(pMole,"TestList");
pArgs=PyTuple_New(1);
pList=PyList_New(0);
for(inti=0;i<3;i++)
{
PyList_Append(pList,Py_BuildValue("i",i));
}
PyTuple_SetItem(pArgs,0,pList);
pRet=PyEval_CallObject(pFunc,pArgs);
Py_Finalize();
最後輸出的:[0, 1, 2]