Manipulating raw data in Python

Looney, James B james.b.looney at lmco.com
Tue Aug 21 11:12:26 EDT 2007


How do I get access to a data buffer in Python so that I can directly
view/modify the data?  My buffer size is 256 (for this specific case)
bytes.  Most of the time, I access want to access that data in 4-byte
chunks, sometimes in single byte chunks.  How do I go about doing so?

I'm certain someone's come across (and has probably asked this question
a few times).  I've tried various searches, and I'm either missing the
obvious, or am not using the right key words to get what I'm looking
for.  I mostly get back results about audio, files, etc.  In my case,
I'm using an HDLC protocol.

A little background:
I've got a socket connection.  On the server side is C++ code.  On the
client (Python) side, I have a SWIG-ified C++ extension.  The extension
is my messaging API, so that I can interact with the socket in a known
manner on both sides of the connection.  In C++, I'd usually just use a
method like "char *getBuffer()". However, Python seems to want to treat
this as a string even though it really isn't.  I usually only get a few
bytes before Python encounters data which looks like a NULL.

Any help is appreciated.
Thanks,
-JB
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20070821/5cd37461/attachment.html>


More information about the Python-list mailing list