pack and unpack problems

Justin Johnson justinjohnson at fastmail.fm
Tue Jun 17 21:43:03 EDT 2003


Hi,

I've been trying to do some work with struct's pack and unpack.  I'm
having a hard time though, because I'm used to perl's sizes, but things
aren't working as expected in python.  In perl I could do...

my ($a, $b) = unpack 'xxNxxH8', $data;

So I tried to convert it to python as...

a, b = unpack('xxLxx8c', data)

Note I used c instead of H cause I wasn't sure what to replace H with.  I
get the following error...

exceptions.ValueError: unpack tuple of wrong size

struct.calcsize('xxLxx8c') returns 18, which is the amount of bytes in
"data", at least I think so.  I'm not sure what's going on here.  Anybody
have any advice on this?

Thanks.
-Justin





More information about the Python-list mailing list