// If my MyPython.py file is in "/Users/xx/code", set the working path to "/Users/xx/code" std::string path = "/Users/xx/code"; PySys_SetPath(&path[0u]);
// Import MyPython.py module PyObject* pModule = PyImport_ImportModule("MyPython"); if (!pModule) { std::cout <<"Cannot open Python file!\n"; returnfalse; }
// Get the HelloPython() function in the module PyObject* pFunhello = PyObject_GetAttrString(pModule, "HelloPython"); if (!pFunhello) { std::cout << "Failed to get this function!"; returnfalse; }