parse binary file

contro opinion contropinion at gmail.com
Sun Jan 29 02:51:39 EST 2012


please download the attachment ,and put in  c:\test.data

and run the folloeing code:

from struct import unpack
file_obj = open('c:\\test.data', 'r')
day = file_obj.read(40)
while day:
            parsed = list(unpack('LLLLLLL', day[:28]))
            print parsed
            day = file_obj.read(40)




[20081014, 2139065, 2146730, 2016184, 2017321, 53353969, 81131895]
wi2mt

[20081015, 1995885, 2013491, 1963103, 1994667, 29604089, 47896861]
xi2å<

[20081016, 1916133, 1943320, 1901503, 1909941, 35148740, 59837806]
yi22S

[20081017, 1921842, 1941299, 1902598, 1930651, 26152709, 45736073]
|i2T\

[20081020, 1924180, 1979840, 1890920, 1974010, 32116330, 54057592]
}i221

[20081021, 1978674, 1996658, 1956110, 1958529, 38697702, 62318899]
~i2ナ}

[20081022, 1932677, 1950791, 1894310, 1895822, 32351379, 53899980]
i2{?

[20081023, 1851259, 1879849, 1828308, 1875561, 32972464, 54004501]
タi2ᆵ゙

[20081024, 1875631, 1888101, 1825526, 1839621, 31704770, 51634501]
テi2Iロ

Traceback (most recent call last):
  File "C:\data.py", line 5, in <module>
    parsed = list(unpack('LLLLLLL', day[:28]))
error: unpack requires a string argument of length 28


why i can't  parse all of them??i just can get  a small  part of them.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20120129/e516dbf6/attachment.html>


More information about the Python-list mailing list