[docs] [issue22232] str.splitlines splitting on non-\r\n characters

Neil Schemenauer report at bugs.python.org
Fri Oct 5 14:13:08 EDT 2018


Neil Schemenauer <nas-python at arctrix.com> added the comment:

> Why not simply add a new parameter, to make people who want ASCII linebreaks continue to use .splitlines() ?

That could work but I think in nearly every case you don't want to use splitlines() without supplying the parameter.  So, it seems like a bit of trap for new users.  Worse, because in Python 2, str.splitlines() does what they want, they will do the simple thing which is likely wrong.

If we do stick with just splitlines(), perhaps it should get a 'newline' parameter that mostly matches io.open (i.e. it controls universal newline behavior).  So if you don't want to change behavior, str.splitlines(newline=None) would split as it currently does.  To make it split like io files do, you would have to do newline='\n'.

To me, it seems attractive that:
fp.readlines() == fp.read().iterlines()

You suggestion would make it something like:
fp.readlines() == fp.read().splitlines(newline='\n')

I guess I could live with that but it seems unnecessarily ugly and verbose for what is the most common usage.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue22232>
_______________________________________


More information about the docs mailing list