How to represent a sequence of raw bytes

Hrvoje Niksic hniksic at
Mon Dec 22 08:40:40 CET 2008

"Steven Woody" <narkewoody at> writes:

> What's the right type to represent a sequence of raw bytes.  In C,
> we usually do
> 1.  char buf[200]  or
> 2.  char buf[] = {0x11, 0x22, 0x33, ... }
> What's the equivalent representation for above in Python?

import array
buf = array.array('b', [0x11, 0x22, ...])

It automatically retrieves byte values without having to call ord(),
and it allows changing them.  It also has a C API for getting to the
address of the underlying buffer.

More information about the Python-list mailing list