Reading from a binary file in a portable way

Sean 'Shaleh' Perry shalehperry at attbi.com
Thu Apr 18 02:45:46 EDT 2002


On 18-Apr-2002 jb wrote:
> 
> I should like to read a (binary) file x.y in a buffer and then do things 
> like getting the 16 bit integer that is at the offset n, n+1 in the file 
> (maybe lowbyte, then higyhbyte.
> 
> Previously I did it only under MS-Windows where for example I could open the 
> file with the flag O_BINARY but this is no longer possible under Linux.
> 
> What would a solution that works under both Unix and MS-Windows look like?
> 

Why can't you open the file in binary mode under Linux/UNIX?

You may also find the 'struct' module useful.





More information about the Python-list mailing list