[Numpy-discussion] ctypes, numpy-array

Mark Heslep mark at mitre.org
Tue Jul 25 11:52:28 CDT 2006

Christopher Barker wrote:
> Lars Friedrich wrote:
>> I would like to work with some data using python/numpy. The data is
>> generated with C. To bring the data from C to python, I would like to
>> use ctype. I am using python 2.4.3 on a windows-System.
>> To accomplish the described task, I have the following plan. Please tell
>> me, if this is possible, respectively if there is a better way.
>> 1) In C, I write a .dll, that has a function
>> int foo(PyObject *arg)
> I'm a bit confused here. I thought the primary point of ctypes was to be 
> able to access existing, non-python-aware dlls from Python without 
> writing C code.
> In this case, you're writing a dll that understands PyObjects (or, I 
> assume, a particular PyObject -- a numarray). Why not just forget ctypes 
> and write a regular old extension?
See Albert's post up thread. Agreed, if he was going to go to the 
trouble of using the Py C API then he didn't really need ctypes. What 
the original poster wanted (Im assuming) was something much simpler like

int foo(int* x)

as Albert suggested, and then use the new numpy ctypes atrributes and 
ctypes 'argtypes' type mapping facility to pass the data contained in 
the py object into a simple routine. That then, is the advantage of ctypes.


More information about the Numpy-discussion mailing list