line break confusion

Michael Mell mike at nthwave.net
Sat Feb 16 00:01:18 EST 2002


Sean 'Shaleh' Perry wrote:

> Windows: \r\n
> Linux (UNIX): \n
> Mac: \r
>
> Each OS's libs transform the sequence '\n' to whatever the right thing is for
> them.

Thanks for answering such an apparently ignorant question, but the answer is not
so simple.

I want to read and write files with line breaks which are not of the native
platform type.

Problem #1 is that on a Mac, the values of Mac and Unix are /swapped/ and
therefore wrong. Writing a file using '\n' results in a /Mac/ line break (as
reported by BBEdit, the venerable Mac editor). Writing a file using '\r' results
in a /Unix/ file. The Mac seems unable to write Windows \r\n no matter what
order is used.

Problem #2 is that when reading a Windows file on Linux or Mac, a /single/ line
('\r\n') is interpreted as /two/ lines ('\n\n'). Files written out on Linux then
have double the correct number of lines.

I believe Problem #1 is a bug, and Problem #2 just a fact of life.


--
mike at nthwave.net
llemekim         YahooIM
415.455.8812     voice
419.735.1167     fax






More information about the Python-list mailing list