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

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


> > 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.
> 
> What about the mac where \r *is* the line ending?

Works fine, as long as you only *peek* (i.e. don't actually consume
the character following \r if it is not \n, so it's available for the
next read).  Requires a little smart buffer handling, which is one
reason why it's hard to do using regular stdio.  Also, interactive
input must be treated special (so that if the user types "foo"
followed by \r, the peek doesn't force the user to type another line
just so that we can peek at the character following the \r).

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