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]