test.py
def add(a,b):
""" """
print a,b,a+b
return a+b
c program
#include <python.h>
int _tmain(int argc, _TCHAR* argv[])
{
try
{
PyObject *pName,*pModule,*pDict,*pFunc,*pArgs1,*pArgs2,*pOutput;
Py_Initialize();
if(!Py_IsInitialized())
return -1;
pModule=PyImport_ImportModule("test");
pDict=PyModule_GetDict(pModule);
pFunc=PyDict_GetItemString(pDict,"add");
pArgs1=Py_BuildValue("ii", 1,2);
//pArgs2=Py_BuildValue("i", 2);
pOutput=PyEval_CallObject(pFunc,pArgs1);
int c=0;
PyArg_Parse(pOutput, "d", &c);
cout<<c;
//PyRun_SimpleString("");
Py_Finalize();
}
catch(exception* ex)
{
cout<<ex->what();
}
char c;
cin>>c;
return 0;
}
Console print nothing and closed.
What's wrong?
Thanks!