All Topics
All Topics
Technology
Technology
Design
Design
Programming
Programming
Science
Science
News
News
Gaming
Gaming
Entertainment
Entertainment
Business
Business
Finance
Finance
Sports
Sports
Health
Health
Food
Food
Travel
Travel
Art
Art
Music
Music
Books
Books
Education
Education
Politics
Politics
Personal
Personal
No algorithm. No AI slop. No ads. Just RSS. Pro-human. Indie writers. Real journalism. Open web. Chronological. Hand toasted.

Python's splitlines() Method Handles More Line Boundaries Than Just Newlines

By

Bogdanp

7mo ago· 2 min readenInsight

Summary

The article reveals that Python's str.splitlines() method splits strings on more line boundaries than just the common newline characters (\n, \r, \r\n). It actually handles a superset of universal newlines including line tabulation (\v), form feed (\f), file separator (\x1c), group separator (\x1d), and record separator (\x1e). The author shares this discovery after being surprised by the method's broader functionality beyond what they initially assumed.

Key quotes

· 3 pulled
This method splits on the following line boundaries. In particular, the boundaries are a superset of universal newlines.
I always assumed that Python's str.splitlines() split strings by 'universal newlines', i.e., \n, \r, and \r\n. But it turns out it does a lot more than that.
The boundaries are a superset of universal newlines.
Snippet from the RSS feed
(With thanks to Seth Larson for taking me down this rabbit hole.)

You might also wanna read