2

When I tried this code:

PyRun_SimpleString("print('hello')");

it works.

but when I tried this code:

PyObject* modStr = PyBytes_FromString((char*)"test");
PyObject* mod = PyImport_Import(modStr);
PyObject* pFunc = PyObject_GetAttrString(mod, (char*)"mul");
PyObject* args = PyTuple_Pack(2, 2.3,4.1);
PyObject* pVal = PyObject_CallObject(pFunc,args);
double result = PyFloat_AsDouble(pVal);

it raises an access violation.

N.B.: my python file called: test.py and it contains a function called mul(a,b) that return just a*b.

How to solve the problem? thanks

minTo
  • 21
  • 1

0 Answers0