Boost logo

Boost Users :

Subject: Re: [Boost-users] [boost-users][python]
From: Germán Diago (germandiago_at_[hidden])
Date: 2009-05-01 11:27:05


I found the line of code that makes this error occur. It is when trying
to push my object into the container.

¿Anyone knows why?

2009/5/1 Germán Diago <germandiago_at_[hidden]>:
> 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)
>   {
>      v.push_back(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):
>         MyBaseClass.__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);
>       v.push_back(m);
>   }
>
> };
>
> 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 hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net