#include "stdafx.h"#include "Python.h"
#include <iostream>
#pragma comment( lib, "python22.lib" )
int _tmain(int argc, _TCHAR* argv[])
...{
Py_Initialize();
PyObject * module;
PyObject * dict;
PyObject * obj;
long lval;
PyRun_SimpleString("obj = (3 * 5)+8");
module = PyImport_AddModule("__main__");
dict = PyModule_GetDict(module);
obj = PyMapping_GetItemString(dict, "obj");
if (obj != NULL)
...{
lval = PyInt_AsLong(obj);
printf("obj: %d ", lval);
}
else
...{
printf("Object not found ");
}
return 0;
}
用python 在c++计算数学表达式的例子
最新推荐文章于 2023-02-10 15:38:09 发布