On 11/2/06, Travis Oliphant email@example.com wrote:
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.
Yes, some other messages I read since I posted this clarified it for me. Essentially, as a Python programmer, there's nothing in the PEP for me - it's for extension writers (and maybe writers of some lower-level Python modules? I'm not sure about this). So as I'm not really the target audience, I won't comment further.
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:
b = buffer(bytestr, format=data_format_object)
a = numpy.frombuffer(b) a['field1'] # prints data stored in the field named "field1"
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?
Somewhat. My understanding is that the python-level buffer object is frowned upon as not good practice, and is scheduled for removal at some point (Py3K, quite possibly?) Hence, any code that uses buffer() feels like it "needs" to be replaced by something "more acceptable". So although I understand the use you suggest, it's not compelling to me because I am left with the feeling that I wish I knew "the way to do it that didn't need the buffer object" (even though I realise intellectually that such a way may not exist).