[Python-Dev] PEP: Adding data-type objects to Python
Travis Oliphant
oliphant.travis at ieee.org
Thu Nov 2 02:08:41 CET 2006
Paul Moore wrote:
>
>
> Enough of the abstract. As a concrete example, suppose I have a (byte)
> string in my program containing some binary data - an ID3 header, or a
> TCP packet, or whatever. It doesn't really matter. Does your proposal
> offer anything to me in how I might manipulate that data (assuming I'm
> not using NumPy)? (I'm not insisting that it should, I'm just trying
> to understand the scope of the PEP).
>
What do you mean by "manipulate the data." The proposal for a
data-format object would help you describe that data in a standard way
and therefore share that data between several library that would be able
to understand the data (because they all use and/or understand the
default Python way to handle data-formats).
It would be up to the other packages to "manipulate" the data.
So, what you would be able to do is take your byte-string and create a
buffer object which you could then share with other packages:
Example:
b = buffer(bytestr, format=data_format_object)
Now.
a = numpy.frombuffer(b)
a['field1'] # prints data stored in the field named "field1"
etc.
Or.
cobj = ctypes.frombuffer(b)
# Now, cobj is a ctypes object that is basically a "structure" that can
be passed # directly to your C-code.
Does this help?
-Travis
More information about the Python-Dev
mailing list