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

Alex Mohr amohr at pixar.com
Wed Jun 27 20:12:18 CEST 2007


Craig Finch wrote:
> Thank you for the suggestion--unfortunately it does not seem to work
> for me.  In my Python code, I verified that the list is composed of
> different types of objects.  However, in C++ I tried
> 
> std::cout << typeid(extract<baseclass&>(myList[j])).name();
> 
> and it shows that all of the extracted objects are of the same class
> (baseclass).  Any other ideas?  I want to be able to do the following
> in C++:
> 
> for (i=0 to length of list)
>    list[i].evaluate();
> 
> where the "evaluate" method is different depending on what kind of
> object is pulled from the list.

Sorry if this feels like an "is it plugged in" type of question, but 
your baseclass is polymorphic (has virtual methods) right?  And when you 
wrap the derived classes, you use boost::python::bases<> to inform the 
library of the hierarchy, yes?

If you could post a minimal, complete example, it would be easier to 
diagnose the problem.

Alex



More information about the Cplusplus-sig mailing list