[Python-Dev] [python] Re: New lines, carriage returns, and Windows

Terry Reedy tjreedy at udel.edu
Tue Oct 2 05:20:15 CEST 2007


"Nick Maclaren" <nmm1 at cus.cam.ac.uk> wrote in message 
news:E1IcGcQ-0002Hf-JZ at virgo.cus.cam.ac.uk...
| The question is independent of what the outside system believes a
| text file should look like, and is solely what Python believes a
| sequence of characters should mean.  For example, does 'A\r\nB'
| mean that B is separated from A by one newline or two?

The grammar presupposes that Python code is divided into lines.  Any 
successful interpreter must adjust to the external source's idea of line 
endings.  This is implementation, not language definition.

The grammar itself has no notion of structure within Python string objects. 
The split method lets one define anything as chunk separators.

The builtin compile method that uses strings as code input specifies \n and 
only \n as a line ending.  The universal line-ending model of string output 
to files does the same.  So from either viewpoint, the unambiguous answer 
to your question is 'one'.

Terry Jan Reedy





More information about the Python-Dev mailing list