[Python-Dev] RE: [Pythonmac-SIG] Mac Python and line-endings

Guido van Rossum guido@python.org
Tue, 18 Sep 2001 15:03:10 -0400


> I'm not aware of any type of text file, that supports switching line
> deliminators inside of the same file....
> 
> Now that doesn't mean it couldn't exist, but logically that would be
> a strange file....
> 
> I think it's a even bet that a file would have the same deliminator
> throughout the file.

I have observed this on Windows, where the text editor in VC++ can
read files with \n line endings, and doesn't change those when it
writes the file back, but always adds \r\n to lines it adds.  So if
you edit a file containing only \n line endings, inserting a few
lines, you have mixed line endings.

Also, Java supports this, and the algorithm to support it is not
difficult: to read a line, read until you see either \r or \n; if you
see \r, peek one character ahead and if that's a \n, include it in the
line.

(Haven't had the time to read the whole proposal, but a Java style
text file implementation has been in my wish list for a long time.)

--Guido van Rossum (home page: http://www.python.org/~guido/)