#include <iostream>
#include <string>
#include <Python.h>
using namespace std;
int main()
{
//初始化
Py_Initialize();
//PyRun_SimpleString("print '12'"); 单句执行
PyObject* pMod = NULL;
PyObject* pFunc = NULL;
PyObject* result = NULL;
//导入模块
pMod = PyImport_ImportModule("helloworld");
if(pMod)
{
//获取函数地址
pFunc = PyObject_GetAttrString(pMod, "Hello");
if(pFunc)
{
//函数调用
result=PyEval_CallObject(pFunc, NULL);
}
//返回类型转换
char* name;
PyArg_Parse(result, "s", &name);
cout<<name<<endl;
}
return 0;
}