Boost logo

Boost :

From: rwgk (rwgk_at_[hidden])
Date: 2002-02-07 14:00:28


--- In boost_at_y..., V Jovanovic <canontriplex_at_y...> wrote:
> From the available documentation, besides strings, I
> don't see how to pass python complex types to my c++
> methods in boost.python.
> For example how would I pass a list ...
>
> >>> import myclass
> >>> l=myclass.reverse([1,2,3])
> >>> l
> [3,2,1]
>
> or how would I pass a dictionary in and out of the
> method?

There are two examples that you might want to look at:

boost/libs/python/example/pickle3.cpp
boost/libs/python/example/do_it_yourself_convts.cpp

The pickle3.cpp function world_getstate() shows how
you can process a python tuple or dictionary.
If you follow this route, your reverse() function
must expect a python tuple. Look at the
getting_started2.cpp example (very bottom) to see
how this can be done with an unbound helper function
without obscuring your C++ interface.

The do_it_yourself_convts.cpp example shows how you
can establish general mappings from Python types
to arbitrary C++ types. I am using this approach
to map Python tuples to boost arrays.

Ralf


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