returning a python array from a C extension

Gary Richardson garyr at fidalgo.net
Tue May 28 10:42:22 EDT 2002


"Maxwell Todd Sayles" <sayles at cpsc.ucalgary.ca> wrote in message
news:3CF29A3D.5EF81E74 at cpsc.ucalgary.ca...
> in python i can write:
>
> from array import *
> a = array ('B', 'some test data')
>
> and a refers to an array object.
>
> now i have a C extension for python that returns a PyString, and within
> python i can convert it to an array
>
> e.g.:
>
> from array import *
> from MyCExtension import *
> a = array ('B', cfunction())
>
> but this method requires an extra copy and construction from the string
> to the array.
>
> is there a way i can have cfunction return a python array?  i tried
> looking through the include files with the Python/C API and couldn't
> find anything.  any help would be appreciated.
>
> Thanks, Maxwell Sayles
>

I've written a wrapper using CXX that passes Python array information
to/from some C functions (FFTW). I'll be glad to send you some
example Python code and the C wrapper if that would be of interest.

Gary Richardson






More information about the Python-list mailing list