Py_BuildValue() and C++ arrays

Erno Kuusela erno-news at erno.iki.fi
Thu Apr 4 10:14:37 EST 2002


In article
<3cac101d$0$25808$6e365a64 at newsreader02.highway.telekom.at>, "Matthias
Stern" <mstern at aon.at> writes:

| I want to return the values "numElem" (int), "unit" (char[250]) and the
| array "data" (float,10000).
| What is the correct syntax for "Py_BuildValue( ??? )" ?

look in <URL: http://www.python.org/dev/doc/devel/ext/buildValue.html>.
note that you don't have to use Py_BuildValue, it's just
a helper for creating various python objects.

| The first two parameters work e.g. this way:
| ---
|      :
|      Py_BuildValue("(si)", unit, numElem);
|      :
| ---

| But how can i send back the data array?!? I cant't write it like this:
| ---
|      Py_BuildValue("(iiiiiiiii... (10.000 time)... iiiii)",  data);
| ---

that would create a tuple, like the Py_BuildValue docs say:

> "(items)" (tuple) [matching-items]
>    Convert a sequence of C values to a Python tuple with the same
>    number of items.

so you can use the PyTuple_* functions.

i don't think the array module exposes a c api, so for arrays you need
to use PyObject_CallObject on array.array and so on (i think).

  -- erno



More information about the Python-list mailing list