open() in binary vs. text mode
sjmachin at lexicon.net
Sat Mar 22 02:35:49 CET 2003
Hal Wine <hal_wine at yahoo.com> wrote in message news:<3E7A80F3.3030303 at yahoo.com>...
> P.S. if you know the file is a text file (but perhaps from
> another platform), you can normalize the input string thusly:
> contents = open( "foo", "rb").read()
> contents.replace( '\x0d\x0a', '\n' )
> contents.replace( '\r', '\n' )
Or just [no pun intended] use the new (in Python 2.3) "rU" (universal
text format) ...
> Now contents looks like a native platform text string. (I _think_
> all the platforms that used LFCR as a separator are long dead now...)
What platforms used LFCR? I had to deal once upon a time with a data
source that provided files that used LFCR but I just assumed that they
were crazy ...
More information about the Python-list