c/c++ note

此次需要解决c/c++调用python脚本和函数的问题,特做此笔记。

简单调用low level:PyRun_SimpleString("print 'Hello World'")

high level: 导入python模块 p_name=PyString_FromString("1")

python c API 里调用python函数 打印PyObject_CallObject(p_func, NULL) or PyObject_CallFunctionObjArgs

PyObject* PyTuple_New(Py_ssize_t len) 新建参数元组

int PyTuple_SetItem(PyObject *p, Py_ssize_t pos, PyObject *o)

p 设置的参数元组,pos设置元素A的位置,o是所添加元素的值,Py_BuildValue主要提供格式化的参数类型,整数,浮点数,字符串等,用法 http://docs.python.org/release/1.5.2p2/ext/buildValue.html

函数声明:1、有返回值:int f(int n), 2、不需要返回值:void f(int n), 3、执行函数结果顺利0,否-1

函数声明与函数定义

形式参数与实际参数

内部函数:static 类型名 函数名 (形参表),static int max(int a, int b)

外部函数:extern int max(int a, int b)

猜你喜欢

转载自blog.csdn.net/luoluo19550418/article/details/81102602