[Python-3000] Some notes on newline conversion.

Alexandre Vassalotti alexandre at peadrop.com
Fri Dec 28 08:19:26 CET 2007


Hi,

I had a hard time, earlier today, figuring out what was the rules for
converting newline characters (only from the code of
io.TextIOWrapper). So, I wrote some notes for myself. I don't know if
there's any documentation about this yet -- that is why am posting my
notes to the list. Free it to use them for whatever you want to.

Cheers,
-- Alexandre


Known newline type:
  LF: \n or "universal newline"
  CRLF: \r\n
  CR: \r

Argument |
value    | Notes
---------+-------------------------------------------------------
None     | Default mode for open().
         | LF are converted to the value of os.linesep on writes.
         | Convert any known newline type to LF on reads.
         | Readline splits on LF.
---------+-------------------------------------------------------
""       | No conversions on writes.
         | No conversions on reads.
         | Readline splits on any known newline type.
---------+-------------------------------------------------------
LF       | Default mode for StringIO.
         | No conversions on writes.
         | No conversions on reads.
         | Readline splits on LF.
---------+-------------------------------------------------------
CRLF     | Convert LF to CRLF on writes.
         | No conversions on reads.
         | Readline splits on CRLF.
---------+-------------------------------------------------------
CR       | Convert LF to CR on writes.
         | No conversions on reads.
         | Readline splits on CR.
---------+-------------------------------------------------------


More information about the Python-3000 mailing list