官方网站 https://docs.python.org/2.6/
选择你安装的python版本;
1.
Py_BuildValue("s", "YaoYin") 等于 python中的 定义了一个字符串'YaoYin'
2.
PyObject *pDict = PyDict_New();
PyDict_SetItemString(pDict, "Name", Py_BuildValue("s", "YaoYin"));
等于
python中的
pDict = []
pDict["Name"] = "YaoYin"
3. PyObject *pArgs = PyTuple_New(1);
PyTuple_SetItem(pArgs, 0, pDict);//0---序号将字典类型变量添加到参数元组中
等于python中的
pArgs = (pDist,) 注意逗号不能省
4.
pReturn = PyEval_CallObject(pFunc, pArgs);//调用函数
等于python中的
apply(pFunc,pArgs)或者pFunc(*pArgs) 说明: * 的含义是 pArgs为元组
5.
int size = PyDict_Size(pReturn);
等于python中的
size = len(pReturn)
6.
PyObject *pNewAge = PyDict_GetItemString(pReturn, "Age");
等价
pReturn['Age']
7.
int newAge;
PyArg_Parse(pNewAge, "i", &newAge);
将python类型转为c类型
44.
本文详细解析了Python编程中的高级特性与操作方法,包括数据类型转换、元组使用、参数传递、函数调用、返回值处理以及类型转换等核心概念。通过具体的代码实例,帮助读者更好地掌握Python的高级编程技巧。
572

被折叠的 条评论
为什么被折叠?



