您的位置:首页 > 编程语言 > C语言/C++

c++调用python的入门例子

2009-03-19 18:09 996 查看
#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;
}


 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  python c++ null import c