#include#include#includeintmain(intargc,char*argv[])
{
Py_Initialize();if(!Py_IsInitialized())
{return-1;
}
PyRun_SimpleString("import sys");
PyRun_SimpleString("sys.path.append('./')");
PyObject*pName;
PyObject*pModule;
PyObject*pDict;
PyObject*pFunc;
pName=PyString_FromString("api");
pModule=PyImport_Import(pName);if(!pModule)
{
printf("can't find call.py");
getchar();return-1;
}
pDict=PyModule_GetDict(pModule);if(!pDict)
{return-1;
}
{
pFunc=PyDict_GetItemString(pDict,"load_test");if(!pFunc||!PyCallable_Check(pFunc))
{
printf("can't find function [test]");
getchar();return-1;
}
PyObject*pFn=PyObject_CallObject(pFunc,0);char*buffer=PyString_AsString(pFn);
printf("%s\n",buffer);
PyObject*o=Py_CompileString(buffer,"none",Py_file_input);
PyObject*m=PyImport_ExecCodeModule("a.a",o);
PyObject*d=PyModule_GetDict(m);
pFunc=PyDict_GetItemString(d,"add");if(!pFunc||!PyCallable_Check(pFunc))
{
printf("can't find function [add]");
getchar();return-1;
}
PyObject*args=PyTuple_New(2);
PyTuple_SetItem(args,0,Py_BuildValue("l",3));
PyTuple_SetItem(args,1,Py_BuildValue("l",4));
PyObject*pAdded=PyObject_CallObject(pFunc,args);intret=PyInt_AsLong(pAdded);
printf("add value:%d\n",ret);
}
Py_Finalize();
system("PAUSE");return0;
}