How can I represent a byte array (like in Java with byte[]) in Python? I'll need to send it over the wire with gevent.
byte key[] = {0x13, 0x00, 0x00, 0x00, 0x08, 0x00};
How can I represent a byte array (like in Java with byte[]) in Python? I'll need to send it over the wire with gevent.
byte key[] = {0x13, 0x00, 0x00, 0x00, 0x08, 0x00};
In Python 3, we use the
bytes
object, also known asstr
in Python 2.I find it more convenient to use the
base64
module...You can also use literals...
An alternative that also has the added benefit of easily logging its output:
allows you to do easy substitutions like so:
Dietrich's answer is probably just the thing you need for what you describe, sending bytes, but a closer analogue to the code you've provided for example would be using the
bytearray
type.Just use a
bytearray
(Python 2.6 and later) which represents a mutable sequence of bytesIndexing get and sets the individual bytes
and if you need it as a
str
(orbytes
in Python 3), it's as simple as