I've written something like this far too many times:

lines = (line.rstrip('\n') for line in open(frame).readlines())

It's not unworkable, but it's definitely common to want the lines without
the newlines. The corresponding .writelines() hits me less, but it's still
a concern.

I slightly shorter and more intuitive spelling would be convenient. On the
model of print(), it seems like a 'sep=' argument would make sense, while
being backwards compatible. Obviously the default would need to be current
behavior.

On Tue, Jul 13, 2021, 10:08 AM Christopher Barker <python...@gmail.com>
wrote:

> On Tue, Jul 13, 2021 at 9:00 AM <2qdxy4rzwzuui...@potatochowder.com>
> wrote:
>
>> As it stands, writelines is consistent with readlines.  Both preserve
>> newlines.
>>
>
> indeed. so if this idea is to be done (and there's something to be said
> for it), I think a similar option should be added to readlines as well --
> striping the newline.
>
> A couple other notes:
>
> This would highlight the whole "a string is an iterable of strings"
> problem :-( -- should strings be special cased? I think not, that's an
> issue that Python programmers have to learn at one point or another anyway.
>
> As for whether it always puts in a newline, or if you can specify what you
> want to put in , I vote for the newline -- newlines are not the same on all
> platforms (though TextIO does translate), but I think it would get a bit
> confusing if someone explicitly put in "\n| and got "\r\n".
>
> And the name IS writeLINES -- so why would anyone expect to use it for
> anything else -- we still have str.join() after all.
>
> -CHB
> --
> Christopher Barker, PhD (Chris)
>
> Python Language Consulting
>   - Teaching
>   - Scientific Software Development
>   - Desktop GUI and Web Development
>   - wxPython, numpy, scipy, Cython
> _______________________________________________
> Python-ideas mailing list -- python-ideas@python.org
> To unsubscribe send an email to python-ideas-le...@python.org
> https://mail.python.org/mailman3/lists/python-ideas.python.org/
> Message archived at
> https://mail.python.org/archives/list/python-ideas@python.org/message/TWZHPL7ZP3MQTIAAQTEAOWZW43P3LIW3/
> Code of Conduct: http://python.org/psf/codeofconduct/
>
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/UC2B7WUOVOH7FCJ3SRNPLYK7FYZ25EMA/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to