[C++-sig] Extracting C++ objects of different types from a Python list

Craig Finch oanjao at yahoo.com
Wed Jun 27 00:01:24 CEST 2007

I have run into a problem that I don't know how to solve with
Boost.python, and I can't find the answer online.  I have a list of
objects in Python, and the objects are of different classes.  All the
classes are derived from a common base class, and the classes are
defined in C++ and exposed to Python.  The list of objects is created
in Python, and I would like to get this list into C++, where the the
objects of different types will be handled differently.  I can bring
the list into C++ as a boost::python::list, but then I have to use
extract <type> to get the individual objects from the list.  The
problem is that extract<baseclass> works, but then all of the extracted
objects are the same type.  The information contained in the derived
types is lost.

Is it possible to do this with boost.python?  Should I be thinking of a
 different way to design the code so that I can pass in a list of
objects from a single class?
       Craig Finch

Please reply to cfinch at ieee.org

Sick sense of humor? Visit Yahoo! TV's 
Comedy with an Edge to see what's on, when. 

More information about the Cplusplus-sig mailing list