noob stuck on reading double

Joe Riopel goon12 at gmail.com
Tue Jan 29 13:59:27 EST 2008


On Jan 29, 2008 1:35 PM, Hannah Drayson <hannah.drayson at plymouth.ac.uk> wrote:
> It imports as a string of rubbish...
> i.e.
>
> <open file 'data.bin', mode 'rb' at 0x5a2a8>
> >>> text = f.read()
> >>> print text
> ?F?C??y??>?
> @?ӜI at g[??B8~??????Q???Q???Q???Q???Q???Q???Q???Q???Q???Q????=N@???????????????????/???8@@@@?Q at E??/??T at N#????S@?????Q???Q???Q???Q???Q??Ǒ????????R[???Q???????
> >>> unpack('d', text)
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
>   File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/struct.py", line 87, in unpack
>     return o.unpack(s)
> struct.error: unpack requires a string argument of length 8

When reading the file, try using
file = open('data.bin', 'rb')
file.seek(0)
raw = file.read()

Do the unpack on "raw".


More information about the Python-list mailing list