On Tue, Jul 13, 2021 at 09:05:54AM -0700, Christopher Barker wrote: > 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.
I don't think that's as useful as you may expect. When processing lines of text, we often want to strip *any* trailing whitespace, not just newlines. So even if you strip the newline, you probably will still need to strip trailing whitespace. So why bother with stripping the newline? I think it will be extremely niche to want one but not the other. > 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. Sorry, have I missed something? How is this relevant? We're talking about a list of strings. > 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". A precedent is str.splitlines: splitlines(self, /, keepends=False) Return a list of the lines in the string, breaking at line boundaries. Line breaks are not included in the resulting list unless keepends is given and true. except writelines (and readlines) would presumably reverse the default. * readlines default to keeping the newlines * writelines default to not appending newlines > And the name IS writeLINES -- so why would anyone expect to use it for > anything else -- we still have str.join() after all. Repurposing functions to do something different from what the designers imagined is very common. -- Steve _______________________________________________ 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/RMAHTFVD2V7RRW3XKEIPCK2CSTWHOLX2/ Code of Conduct: http://python.org/psf/codeofconduct/