0

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.

Alok
  • 163
  • 1
  • 14
  • Please show a complete (but minimal) example of the Python code. The error has nothing to do with strings but with whatever `np` is. The solution will involve finding out why it is `None`. – MB-F Mar 27 '18 at 06:56
  • Hi Kazemakase.. I edited my code to make it more readable. Honestly, there isn't much I have done yet on Python code to show. I, as of now, just run one line of code that is np.fromstring(...). May I also point out that If I just print the length, type or the whole string straightaway, I am getting the desired output – Alok Mar 27 '18 at 07:30
  • Thanks for the edit. I can't believe this is the complete code that actually produces this error. The error message says that you try to do the equivalent of `None.fromstring`. This means `np is None`. You'll need to find out why. – MB-F Mar 27 '18 at 07:35

0 Answers0