writeable buffer and struct.pack_into and struct.unpck_from

John Machin sjmachin at lexicon.net
Sun Sep 21 12:52:55 CEST 2008


On Sep 21, 3:16 pm, Tzury Bar Yochay <Afro.Syst... at gmail.com> wrote:
> Thanks Gabriel,
> I was missing the information how to create a writable buffer.

array.array objects also have the writable buffer nature:

>>> import array
>>> b = array.array('c', '\0' * 10)
>>> b
array('c', '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
>>> import struct
>>> struct.pack_into('<hhhh', b, 0, 1, 2, -1, -32768)
>>> b
array('c', '\x01\x00\x02\x00\xff\xff\x00\x80\x00\x00')

HTH,
John



More information about the Python-list mailing list