Pages

Showing posts with label byte. Show all posts
Showing posts with label byte. Show all posts

Friday, August 29, 2014

Python: mutable byte array as buffer








bytearray function can be used to make a mutable byte array as buffer:
import struct
buffer = bytearray(8)
buffer[0]=1
buffer[1]=1
struct.pack_into('>ih', buffer, 2, 100, 200)
# to convert the array to str
print(bytes(buffer))

see also