[C++-sig] Re: Creating an array in C++
David Abrahams
dave at boost-consulting.com
Wed Feb 25 01:58:40 CET 2004
CÔTÉ Marc-Alexis <Marc-Alexis.Cote at ino.ca> writes:
> Hello,
>
> I am relatively new to the world of python, so please bear with me if you
> find this question rather basic.
>
> I am writting some python code that interfaces with an image processing
> library that I wrote in C++. Up until now, I have exchanged image data
> (between the c++ library and python) through bitmaps stored in files. I find
> this rather clumsy and I am trying to use boost.python and the
> numeric::array type to help me transfer images from the library in a more
> elegant manner.
>
> My first problem is in creating the numeric::array in the c++ code. Let's
> say that I want a 3 dimensional array of unsigned bytes, would this be a
> correct way to do it?
>
> unsigned char data[300];
> boost::python::numeric::array anArray(&data[0], "UByte",
> boost::python::make_tuple(10,10,3));
>
> This doesn't give an error when I compile it. However, it fails to run as I
> expect it:
>
>>>>TypeError: No to_python (by-value) converter found for C++ type: unsigned
> char
>
> What am I missing?
The error is coming from
boost::python::numeric::array anArray(&data[0], "UByte",
here--------------------------------------^^^^^^^^
What python argument value do you expect to be passed to the python
object's __init__ function?
> Would you even use an array to return the data, or is there a better way?
An array probably makes sense. I guess it depends what type you want
Python users to see on the other side of this function.
--
Dave Abrahams
Boost Consulting
www.boost-consulting.com
More information about the Cplusplus-sig
mailing list