Read binary file and dump data in
sromero at gmail.com
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");
value = fgetc(fp);
printf("%d", value );
I started writing:
fp = open(file, "rb")
data = fp.read()
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