Newbie lost

Anton Vredegoor anton at vredegoor.doge.nl
Wed Feb 25 18:49:27 CET 2004


Angelo Secchi <secchi at sssup.it> wrote:

>
>I'm fighting with a binary file and I am definitely lost.
>I know that each line of the file has a first part that is a string with
>length 113 and then that there is a group of identical fields. I do not
>know the precise format of these fields even if I know that the file was
>created on an IBM Mainframe and that in the binary part there should be
>223 fields with the same width 4.
>Just to give you an idea if I read the first line of my file  as a
>string I obtain something like (just a small part of the first line):
>
>13510010222010341341F\xee;\xb4\x00\x00\x00\x00\x00\x00\x00\x00F]\xe3\x9
>a\x00
>
>
>Still I am not able to convert this binary. Can anybody give some
>advices?

The string above contains escape sequences, so sometimes four
characters correspond to one byte, sometimes a char is just a byte.
This is not really present in the file but just an artifact of the way
you chose to print it. In order to gain more insight:

#open the file in binary mode e.g: 
inf = file('somefile','rb')

#read 1 line e.g:
line = inf.readline()

#turn this line into a list of characters:
L = list(line)

#Inspect the list L and come back here with further questions,
#if you have any :-)
print L

Anton








More information about the Python-list mailing list