Getting C++ object from PyObject *
Nikolai Kirsebom
nikolai.kirsebom.NOJUNK at siemens.no
Thu Sep 25 03:45:31 EDT 2003
I'm using BOOST to integrate Python into our application. Could
someone tell me how I get hold of the C++ object (pointer to the
object instance) from a PyObject *.
Example:
I have defined and exposed two C++ classes:
class MyObjectA
{
public:
MyObject();
};
class MyObjectB
{
public:
MyObjectB();
void SetInput(PyObject *o);
};
In Python I'm able to write:
pa = MyObjectA()
pb = MyObjectB()
to create an instance of each of the classes.
Then using the exposed SetInput method of class MyObjectB:
pb.SetInput(pa)
How would I code the SetInput method:
void MyObjectB::SetInput(PyObject *o)
{
//Check that type of 'o' is an (instance) object of class 'MyObjectA'
//Fetch the pointer (reference) to the actual instance of MyObjectA
MyObjectA * ca = .....
}
Thanks for any help.
Nikolai
More information about the Python-list
mailing list