Packing data
Paul Rubin
phr-n2002a at nightsong.com
Wed May 1 20:37:38 EDT 2002
bvdpoel at uniserve.com writes:
> I'm doing some midi stuff and need to pack ints into a byte string. I'm
> doing
>
> def mkstring(var):
> ret = ""
> for a in var:
> ret += chr(a)
> return ret
>
> Which works. But I got to thinking there might be a more efficient way
> to to this. So I started to look at array and struct.
try this:
import array
def mkstring(var):
a = array.array('B', var)
return a.tostring()
More information about the Python-list
mailing list