Why does Python not return first line?

Steven D'Aprano steven at REMOVE.THIS.cybersource.com.au
Mon Mar 16 21:39:39 EDT 2009


On Mon, 16 Mar 2009 15:20:18 -0700, Falcolas wrote:

> FWIW, I've rarely seen a \r by itself, even in Windows (where it's
> usually \r\n). Unix generally just outputs the \n, so my guess is that
> some other process which created the output removed newline characters,
> but didn't account for the carriage return characters first.


\r is the line terminator for classic Mac. (I think OS X uses \n, but 
presumably Apple applications are smart enough to use either.)

I also remember a software package that allowed you to choose between \r
\n and \n\r when exporting data to text files. It's been some years since 
I've used it -- by memory it was a custom EDI application for a rather 
large Australian hardware company. (Presumably their developers couldn't 
remember which came first, the \r or the \n, so they made it optional.)

The Unicode standard specifies that all of the following should be 
considered line terminators:

LF:    Line Feed, U+000A
CR:    Carriage Return, U+000D
CR+LF: CR followed by LF, U+000D followed by U+000A
NEL:   Next Line, U+0085
FF:    Form Feed, U+000C
LS:    Line Separator, U+2028
PS:    Paragraph Separator, U+2029

http://en.wikipedia.org/wiki/Newline#Unicode

so presumably if you're getting data from non-Windows or Unix systems, 
you could find any of these. Aren't standards wonderful? There are so 
many to choose from.


-- 
Steven



More information about the Python-list mailing list