Reading from a binary file in a portable way

Steve Holden sholden at holdenweb.com
Thu Apr 18 07:30:27 EDT 2002


"jb" <egrossde at yahoo.de> 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?
>
Such a solution would probably use the mmap module. Although there are minor
differences on the two platforms it should be possible to write something
that works well on both.

regards
 Steve







More information about the Python-list mailing list