Search This Blog

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

No comments:

Post a Comment