[Python-Dev] Expose the array interface in Python 2.5?

Sasha ndarray at mac.com
Sat Mar 18 03:19:11 CET 2006


"Travis E. Oliphant" <oliphant.travis <at> ieee.org> wrote:
> It is very important for many people to get access to memory with some
> description of how that memory should be interpreted as an array.
> Several Python packages could benefit if Python had some notion of an
> array interface that was at least supported in a duck-typing fashion.

I have just submited a patch to SF that implements __array_shape__ and 
__array_typestr__ attributes for the array.array class.

These are the only two attributes that are marked "required" in the 
"N-D array interface" document.

I think it makes sense to discuss these two first.  Note that these methods
do not add any new functionality. Shape is just (len(a),) and typestr just
packs endiness information together with a.typecode and a.itemsize.

The only benefit of adding these two methods is to create "one true way"
to access this information.

I am fairly happy with __array_shape__, but __array_typestr__ feels somewhat
archaic.  I would rather see ctypes style data description instead of this
struct style.

I believe unifying the way different python modules describe binary data is a
worthwhile first step in bringing array interface to the core.



More information about the Python-Dev mailing list