I have a python class A
like this.
class A:
def __init__(self, name):
self.name = name
def print_lastname(self, lastname):
print(lastname)
I have to call this code like this.
import B
a = B.A("hello")
a.print_lastname("John")
Currently, I need to use this A
class from my C++ code. I have got this far.
Py_Initialize();
string hello = "hello";
PyObject *module, *attr, *arg;
module = PyObject_ImportModule("B"); // import B
attr = PyObject_GetAttrString(module, "A"); // get A from B
arg = PyString_FromString(hello.c_str());
instance = PyInstance_New(attr, arg, NULL); // trying to get instance of A with parameter "hello"
Py_Finalize();
But I am getting error
Exception TypeError: 'argument list must be tuple' in module 'threading' from '/usr/lib64/python2.7/threading.pyc'
How can I achieve from import
statement to a.print_name("John")
from C++?
Any help is appreciated.