Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

4
  • 8
    note: str.splitlines() treats as newlines many characters (not just \r, \n) Commented Jan 25, 2016 at 6:57
  • This also gives unexpected results if you have a multi-line string and only want to strip the last line-terminator.... (although it can probably by joined back again for that) Commented Dec 31, 2021 at 19:27
  • @GertvandenBerg the method is called splitlines(). If I give it a multi-line string, I don't expect it to strip only the last line, because I literaly told it to split my multi-line string into multiple strings at the line breaks ;) Using it to strip line endings off a single-line string is actually just a useful corner case. Commented May 5, 2022 at 10:51
  • this reads all lines into a list (memory) Commented Feb 27, 2024 at 12:32