[Python-3000] Some notes on newline conversion.

Guido van Rossum guido at python.org
Tue Jan 1 18:15:17 CET 2008


I thought PEP 3016 spells out all the details necessary. And the
docstring for open() in io.py as well. Aren't those enough?

On Dec 27, 2007 11:19 PM, Alexandre Vassalotti <alexandre at peadrop.com> wrote:
> 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.
> ---------+-------------------------------------------------------
> _______________________________________________
> Python-3000 mailing list
> Python-3000 at python.org
> http://mail.python.org/mailman/listinfo/python-3000
> Unsubscribe: http://mail.python.org/mailman/options/python-3000/guido%40python.org
>



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


More information about the Python-3000 mailing list