Creating a PyObject* from a C double*

Joze joze_storme at yahoo.com
Sun Apr 13 09:15:27 CEST 2003


Hi,

As part of a Python extension, i have an array of doubles created in a
C function, which should return a corresponding PyObject* to Python.
The array is meant to be used by Numeric/numarray, but apparently, the
C function cannot directly return a PyArrayObject*.

I see that this question has been asked plenty of times in this
newsgroup before, but i cannot seem to make it work. Basically, my C
function is like this:

static PyObject* my_func( PyObject *self, PyObject *args) {

	/* Here i build a variable X of type double* ...  */
	/* and want to pass it back to Python             */

	return ????;

}

I have tried PyArray_FromDims(), PyArray_FromDimsAndData() but i can't
seem to get it right. Can anyone tell me how this works? I'd be most
grateful.

Thanks a lot !
Joe.




More information about the Python-list mailing list