[Python-Dev] PEP: Adding data-type objects to Python
p.f.moore at gmail.com
Sun Oct 29 18:00:25 CET 2006
On 10/29/06, "Martin v. Löwis" <martin at v.loewis.de> wrote:
> Travis E. Oliphant schrieb:
> > Remember the context that the data-format object is presented in. Two
> > packages need to share a chunk of memory (the package authors do not
> > know each other and only have and Python as a common reference). They
> > both want to describe that the memory they are sharing has some
> > underlying binary structure.
> Can you please give an example of such two packages, and an application
> that needs them share data?
Here's an example. PIL handles images (in various formats) in memory,
as blocks of binary image data. NumPy provides methods for
manipulating in-memory blocks of data. Now, if I want to use NumPy to
manipulate that data in place (for example, to cap the red component
at 128, and equalise the range of the green component) my code needs
to know the format of the memory block that PIL exposes. I am assuming
that in-place manipulation is better, because there is no need for
repeated copies of the data to be made (this would be true for large
If PIL could expose a descriptor for its data structure, NumPy code
could manipulate it in place without fear of corrupting it. Of course,
this can be done by the end user reading the PIL documentation and
transcribing the documented format into the NumPy code. But I would
argue that it's better if the PIL block is self-describing in a way
that avoids the need for a manual transcription of the format.
To do this *without* needing the PIL and NumPy developers to
co-operate needs an independent standard, which is what I assume this
PEP is intended to provide.
More information about the Python-Dev