Just use bytearray (Python 2.6 and later), which represents a volatile byte sequence
>>> key = bytearray([0x13, 0x00, 0x00, 0x00, 0x08, 0x00]) >>> key bytearray(b'\x13\x00\x00\x00\x08\x00')
Indexing gets and sets individual bytes
>>> key[0] 19 >>> key[1]=0xff >>> key bytearray(b'\x13\xff\x00\x00\x08\x00')
and if you need it as str (or bytes in Python 3), it's as simple as
>>> bytes(key) '\x13\xff\x00\x00\x08\x00'
Scott Griffiths Sep 11 '11 at 19:06 2011-09-11 19:06
source share