如何调用C++的“SAMBY”?

2024-09-30 20:36:55 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图用Python/C API调用C++代码中的SAMMY的LAMBDIFY。代码粘贴在下面。你知道吗

const char * file = "sympy";
const char * function = "lambdify";
Py_Initialize();
PyObject* pModuleString = PyString_FromString(file);
PyObject* pModule = PyImport_Import(pModuleString);
PyObject* pFunction = PyObject_GetAttrString(pModule, function);
PyObject* pargs = PyTuple_Pack(2,PyString_FromString("x,y"), PyString_FromString("x+y"));
PyObject* presult = PyObject_CallObject(pFunction, pargs);
Py_DECREF(pModule);
Py_DECREF(pModuleString);
Py_DECREF(pFunction);
Py_DECREF(pargs);
Py_Finalize();

PyObject*presult=blah显示以下错误

Exception AttributeError: "'NoneType' object has no attribute 'f_locals'" in <module 'threading' from 'C:\Anaconda2\Lib\threading.pyc'> ignored

请帮帮我!你知道吗


Tags: 代码pyfunctionfilepyobjectcharconstfromstring