_io.TextIOWrapper.readlines(keepends=True)

So it always leaves \n at the end of lines.

I would like it to have the same argument as str.splitlines(keepends=False), just with different default (for backwards compatibility).

I sometimes find myself writing:

def foo(keepends=False):
    with open(...) as f:
        if keepends:
            lines = f.readlines()
        else:
            lines = f.read().splitlines(keepends=False)
    ...

Such would / should make code:

  1. simpler
  2. faster
  3. more consistent

Thank you for your time and consideration.

2 Likes