Strange problem with structs Linux vs. Mac

Michael Wieher michael.wieher at gmail.com
Sun Mar 16 13:14:31 EDT 2008


try twiddling the unpack prefix, they're probably stored in different binary
formats on the disk...

on the struct helppage, is a list of prefixes, can be like

unpack('=HI',data)
unpack('@HI',data)

etc...

find out which one works on each machine

2008/3/16, jasonwiener <jasynwiener at gmail.com>:
>
> Hi-
>
> I am having a VERY odd problem with unpacking right now.  I'm reading
> data from a binary file and then using a very simple struct.unpack to
> get a long.  Works fine on my MacBook, but when I push it to a Linux
> box,it acts differently and ends up pewking.
>
> here's the code snippet:
>                                 fread.seek(0,0)
>                                 tmp_rebuild = fread.read()
>                                 fread.close()
>                                 tmp_long = tmp_rebuild[0:4]
>                                 print tmp_long.encode('hex')
>                                 print repr(tmp_long)
>
>                                 unpacked_long =  struct.unpack('I',
> tmp_rebuild[0:4])[0]
>                                 print 'unpacked_long: %s' % unpacked_long
>
> my MacBook produces:
> 1ec6f3b4
> '\x1e\xc6\xf3\xb4'
> unpacked_long: 516354996
>
> but on the linux box the same code produces:
> 1ec6f3b4
> '\x1e\xc6\xf3\xb4'
> unpacked_long: 3035874846
>
> the data looks to be the same, but the unpacking seems to treat it
> differently.
>
> Has anyone an idea of why this happens???
>
> Thanks-
> J.
>
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080316/fae6e323/attachment-0001.html>


More information about the Python-list mailing list