[Python-ideas] Iterating non-newline-separated files should be easier

Akira Li 4kir4.1i at gmail.com
Sat Jul 26 04:24:16 CEST 2014


Nick Coghlan <ncoghlan at gmail.com> writes:

> On 26 Jul 2014 04:33, "Andrew Barnert"
> <abarnert at yahoo.com.dmarc.invalid>
> wrote:
>> As I've said before, I don't really like the design for '\r' and '\r\n',
> or the fact that three separate notions (universal-newlines flag, line
> ending for readline, and output translation for write) are all conflated
> into one idea and crammed into one parameter, but I think it's probably too
> late and too radical to change that.
>
> It's potentially still worth spelling out that idea as a Rejected
> Alternative in the PEP. A draft design that separates them may help clarify
> the concepts being conflated more effectively than simply describing them,
> even if your own pragmatic assessment is "too much pain for not enough
> gain".
>

It can't be in the rejected ideas because it is the current behavior for
io.TextIOWrapper(newline=..) and it will never change (in Python 3) due
to backward compatibility.

As I understand Andrew doesn't like that *newline* parameter does too
much:

- *newline* parameter turns on/off universal newline mode
- it may specify the line separator e.g., newline='\r'
- it specifies whether newline translation happens e.g., newline=''
  turns it off
- together with *line_buffering*, it may enable flush() if newline is
  written


It is unrelated to my proposal [1] that shouldn't change the old
behavior if newline in {None, '', '\n', '\r', '\r\n'}.

[1] http://bugs.python.org/issue1152248#msg224016


--
Akira



More information about the Python-ideas mailing list