[Python-Dev] PEP: Adding data-type objects to Python

Josiah Carlson jcarlson at uci.edu
Tue Oct 31 23:59:11 CET 2006


"Paul Moore" <p.f.moore at gmail.com> wrote:
> On 10/31/06, Travis Oliphant <oliphant.travis at ieee.org> wrote:
> > Martin v. Löwis wrote:
> > > [...] because I still don't quite understand what the PEP
> > > wants to achieve.
> > >
> >
> > Are you saying you still don't understand after having read the extended
> > buffer protocol PEP, yet?
> 
> I can't speak for Martin, but I don't understand how I, as a Python
> programmer, might use the data type objects specified in the PEP. I
> have skimmed the extended buffer protocol PEP, but I'm conscious that
> no objects I currently use support the extended buffer protocol (and
> the PEP doesn't mention adding support to existing objects), so I
> don't see that as too relevant to me.

Presumably str in 2.x and bytes in 3.x could be extended to support the
'S' specifier, unicode in 2.x and text in 3.x could be extended to
support the 'U' specifier.  The various array.array variants could be
extended to support all relevant specifiers, etc.


> This is probably all self-evident to the numpy community, but I think
> that as the PEP is aimed at a wider audience it needs a little more
> background.

Someone correct me if I am wrong, but it allows things equivalent to the
following that is available in C, available in Python...

    typedef struct {
        char R;
        char G;
        char B;
        char A;
    } pixel_RGBA;

    pixel_RGBA image[1024][768];

Or even...

    typedef struct {
        long long numerator;
        unsigned long long denominator;
        double approximation;
    } rational;

    rational ratios[1024];

The real use is that after you have your array of (packed) objects, be
it one of the above samples, or otherwise, you don't need to explicitly
pass around specifiers (like in struct, or ctypes), numpy and others can
talk to each other, and pick up the specifier with the extended buffer
protocol, and it just works.

 - Josiah



More information about the Python-Dev mailing list