Hi i'm learning how to use python in c++ and am wondering how I convert the returned python value to something I can use in c++.
Here's my code:
CPyInstance pyInstance;
PyRun_SimpleString("import sys");
PyRun_SimpleString("sys.path.append(\".\")");
CPyObject pName = PyUnicode_FromString("Info");
CPyObject pModule = PyImport_Import(pName);
if (pModule)
{
CPyObject pFunc = PyObject_GetAttrString(pModule, "getTracks");
if (pFunc && PyCallable_Check(pFunc))
{
CPyObject pValue = PyObject_CallObject(pFunc, NULL);
//print the returned string
}
else { std::cout << "Error: function getTracks()\n"; }
}
else { std::cout << "error: no module imported"; }
return 0;
def getTracks():
returnString = ""
for track in results['tracks'][:10]:
returnString += 'track : ' + track['name']
return returnString