Boost logo

Boost Users :

Subject: [Boost-users] [boost-users][python]
From: Germán Diago (germandiago_at_[hidden])
Date: 2009-05-01 10:48:24

I have a question about managing python objects.

I have a base class implemented in c++, which I use in python.

>From python I inherit that class. And the I try to use the python
instance from c++, like this.

//This class has a function which is registered in python. I want to
//be able to register python instances with this class
class AnotherClass {
   void registerobject(const std::string & name, MyBaseClass * a)

//Interface class, which I inherit in python
class MyBaseClass {
   virtual const std::string getData(Object * o) const = 0;

>From python:

class MyPyClass(MyBaseClass):
    def __init__(self):

    def getData(self, o):
        return "hello"

My question is. In order to register that class, namely,
MyPyClass(which is a python class):

can I do it through registerobject?

Or should I implement something like this?:

class AnotherClass {

   void registerobject(const std::string & name, python::object & o)
       MyBaseClass * m = extract<MyBaseClass>(o);


In all two cases I get error_already_set exception when I try to execute the
registerobject function and don't know why.

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