[Pythonmac-SIG] IDE patch to convert UNIX/MSDOS line feeds to carriage returns

Andres Corrada andres@corrada.com
Fri, 21 May 1999 20:04:29 +0000


Funny coincidence, I just spent a couple of hours writing some Python code to
unmangle an Alpha text file that I was looking at on an NT machine. In the
process I noticed that IDLE saves the text files with Unix style line ends
('\n') on NT. Is it the intent of IDLE to enforce Unix-style line ends as the
Python standard? I would prefer to have a settable option that specifies the
line ends I want.

In addition, I noticed that the file I was looking at was mangled by virtue of
going through a Linux server. This meant that it not only had lots of '\r's
but the file ended in '\n\r'. A robust way of fixing this was to first replace
all '\n\r' with '\r', followed by all '\n' by '\r', followed by replacement of
all '\r's by '\r\n'. This guarantees that the file will end in a consistent
format in spite of whatever mangling the line ends suffer.

-------------------------------------------------------
Andres Corrada-Emmanuel    Email: andres@corrada.com
Owner                      http://www.corrada.com/mamey
Mamey                      Phone: (413) 587-9595
-------------------------------------------------------