Read binary file and dump data in

Santiago Romero sromero at
Tue Jan 13 21:02:54 CET 2009


 Until now, all my python programs worked with text files. But now I'm
porting an small old C program I wrote lot of years ago to python and
I'm having problems with datatypes (I think).

 some C code:

 fp = fopen( file, "rb");
 while !feof(fp)
    value = fgetc(fp);
    printf("%d", value );

 I started writing:

 fp = open(file, "rb")
 data =
 for i in data:
   print "%d, " % (int(i))

 But it complains about i not being an integer... . len(data) shows
exactly the file size, so maybe is a "type cast" problem... :-?

 What's the right way to work with the binary data (read 1 byte values
and work with them, dumping them as an integer in this case)?


More information about the Python-list mailing list