I'm trying to create a Python Function from a string and executing it. I just cannot figure it out how to execute it properly. The code I wrote doesn't return the value I would expect, but a Object of Type _PY_NoneStruct
.
string code =
R"(
def test():
return 'hi';
)";
Py_Initialize();
auto main = PyImport_AddModule((char*)"__main__");
auto dict = PyModule_GetDict(main);
auto compiled = Py_CompileString(code.c_str(), "not a file", Py_single_input);
auto func = PyFunction_New(compiled, dict);
auto result = PyObject_CallObject(func, NULL);
What needs to be changed for this code snippet zu execute successfully?
Thank you in advance.