Boost logo

Boost :

From: Marc Paterno (paterno_at_[hidden])
Date: 2001-02-28 10:39:13


Hello,

Thanks to David Abrahams for this instructions on getting
a C++ vector passed back to Python. I now find that the
next step I need to take is to turn a C++ sequence (vector,
list, deque...) of "things" into a Python container of the
same "things". Assume that Python already knows about
"things" (either their basic, like int, or they're
already wrapped). My questions are:

(1) What is the best Python type to turn them into?

My current best thought is: if the C++ sequence is not
to be modified (no push_back, no assignment to places in
the sequence), then use a tuple. Otherwise, use a list.
My rule of thumb:

  returned C++ sequence const reference -> Python tuple
  returned C++ sequence (copy) -> Python list

I'd appreciate suggestions from people more expert in
Python than I.

(2) What functions do I write to control the conversion?
Sometimes I also want to translate the contained items,
so I think I may need to write the from_python and to_python
functions myself. An example of doing so for a fairly
simple case would be very useful to me (and perhaps others).

thanks,
Marc Paterno


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