c++调用python的入门例子

#mytest.py you = 'world!' print 'aaaaaaaa' def hello(): print 'hello,world' hello()

c++调用

#include <Python.h> int main() { Py_Initialize(); PyObject *pModule = NULL; PyObject *pFunc = NULL; PyRun_SimpleString("import sys"); PyRun_SimpleString("sys.path.append('./')"); pModule = PyImport_ImportModule("mytest"); pFunc = PyObject_GetAttrString(pModule, "hello"); PyEval_CallObject(pFunc, NULL); Py_Finalize(); return 0; }

 

你可能感兴趣的:(c++调用python的入门例子)