C++ object in PyObject*?

R

Richard

I am wondering, what is the best way to write a Python module as an
interface to a C++ class? I don't want the C++ object representing the
class to be declared as a global, because then if multiple instances
in Python would be created, they would be using the same C++ object
instance, correct?

So it seems to me that there has to be a way to create an object, and
stick it in PyObject *self, since that is passed as an argument to
each function making up the Python module. Then, if multiple
instances of the Python object would be created, they would be
referencing different C++ objects on the back end. Thoughts?

So something like this:
static PyObject* module_function(PyObject *self, PyObject *args) {
MyCrazyCPPObject myobj;
self.add(myobj);
return Py_Something;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top