[C++-sig] how to extract an instance of arbitrary c++ class from python object?

Renato Araujo renatox at gmail.com
Sun Jul 5 02:27:23 CEST 2009

Hi Alexey,

you can use this example to see how create converter rules in
boost:pyhton: http://www.boost.org/doc/libs/1_39_0/libs/python/doc/v2/faq.html#custom_string

or you can expose you class to pyhon using boost:python in normal way.


On Sat, Jul 4, 2009 at 8:50 PM, Alexey Akimov<alexey.akimov85 at gmail.com> wrote:
> Hi,
> Here is a question.(see Subject title) I am particularly interested in such
> implementation using python.boost library.
> For simple cases I've seen examples, such as:
> int x = extract<int>(obj.attr("Attribute_name"))
> However, when a type T in extract<T>() becomes user-specified things become
> harder. For example,
> suppose I have a type Vector wich is something like:
> class Vector{
> public:
> double x,y,z;
> };
> and want to extract information from python object obj to c++ obect of class
> I've found that there are some converters for some standard types, but I'm
> not able to manage how to do this
> for my class. What should I do in order to make the extract<> function to
> understand how it should convert a python
> object (represented as boost::python::object - something like this) into
> Vector object?
> Again, variant like:
> Vector r;
> r.x = extract<double>(obj.attr("x"))
> ... and so on
> are not interested. I need to make it in one operation.
> Thanks
> Alexey
> _______________________________________________
> Cplusplus-sig mailing list
> Cplusplus-sig at python.org
> http://mail.python.org/mailman/listinfo/cplusplus-sig

Renato Araujo Oliveira Filho

More information about the Cplusplus-sig mailing list