Boost logo

Boost Users :

Subject: [Boost-users] [python] converting C++ object to PyObject
From: Johan Råde (johan.rade_at_[hidden])
Date: 2011-07-27 05:06:16

I have three C++ classes X, Y and Z that I have exported from C++ to
Python using python::class_.

Now I want to write a factory function like

PyObject* f(char c)
     if(c == 'x')
         return new X;
     else if(c == 'y')
         return new Y;
     else if(c == 'z')
         return new Z;
         PyErr_SetString(PyExc_ValueError, "Bad function argument");

and export that function to Python.

What is missing here is code that converts X*, Y* and Z* to PyObject*.
How do I write that?

Thank you,

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at