Boost logo

Boost :

From: David Abrahams (david.abrahams_at_[hidden])
Date: 2002-02-13 18:56:45


----- Original Message -----
From: "Dominic Sacré" <bugcreator_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Wednesday, February 13, 2002 6:26 PM
Subject: [boost] Boost.Python: Get a pointer to my C++ class from a
PyObject*

> I have a C++ class A, which is exported to Python. In Python, I define
> another class B, which is derived from A. I then create an object of class
B
> in Python, and on the C++ side I obtain a PyObject* to that object.
> What I need now is a way to get a pointer to the underlying object of
class A
> from that PyObject*, but I can't figure out how...
>
> I guess this question sounds simple, and maybe there's an obvious answer,
but
> I've spent several hours trying to find a solution for my problem, to no
> avail...
>
> Thanks in advance,
> Dominic

fortunately, it /is/ simple:

A* get_A(PyObject* p) { return from_python(p, boost::python::type<A*>()); }

-Dave


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk