I am very new to the idea of embedding python with C++. I am running into the following problem :
I follow the documentation and am able to convert my string data to a python object and then call the Python Function using code similar to :
const char* blu = "1,2,3,4,5,6,7,8,9" ;
//converting to python object :
args = Py_BuildValue("(s)", blu);
if (!args)
{
PyErr_Print();
Py_DECREF(filterFunc);
qDebug()<< "Error building args tuple";
}
resultObj = PyObject_CallObject(filterFunc, args);
I am also able to print the string from the python console. I would assume that the data is getting passed to the python side. The type(string) in the python returns "type str". My problem is with the code on the python side :
import numpy as np
def attoMainFunction2(Image1, Apod = 0, Z_PadInput = 0, requiredpaddingPTR = 0,FLAGInterferogramCalibration = 0, InterferogramCorrFactorinput = 0):
stringPassedFromC = np.fromstring(Image1,dtype=int,sep=',')
# Further Operations with the Array.Not yet implemented.
# return the results as a string cout.
cout = "0"
return cout
I get the following Error :
File "/Users/devas/PycharmProjects/Vis/MainFile.py", line 260, in attoMainFunction2
np.fromstring(Image1,dtype=int,sep=',')
AttributeError: 'NoneType' object has no attribute 'fromstring'
Error invoking 'filterFunc'
If I use the same python code and pass it a string from another python function. It works OK. Am I missing out on something?
Kindly suggest.
Many thanks in advance.