The seemingly simple task of splitting text into lines is surprisingly complex due to historical and evolving standards. Early computing relied on ASCII, which included control characters like LINE FEED (LF) and CARRIAGE RETURN (CR) for line breaks. Different operating systems adopted various combinations of these, leading to portability issues for plain text. For example, Windows uses CR LF, Unix uses LF, and classic Mac OS uses CR. Python addressed this by introducing "universal newline" mode, recognizing all three common line break formats when opening files. Beyond the traditional CR and LF, ASCII also defined FORM FEED (FF) and VERTICAL TAB (VT), which also cause line breaks. The advent of Unicode introduced seven new code points and the CR LF sequence as line break indicators. These include LINE FEED, LINE TABULATION, FORM FEED, CARRIAGE RETURN, NEXT LINE, LINE SEPARATOR, and PARAGRAPH SEPARATOR. Additionally, Unicode's bidirectional algorithm considers characters with a bidirectional class of 'B' as paragraph separators, which also function as line breaks. These include the INFORMATION SEPARATOR FOUR, THREE, and TWO, also known by their ASCII names FILE SEPARATOR, GROUP SEPARATOR, and RECORD SEPARATOR. In total, Python's splitlines() method recognizes ten distinct code points and one multi-code-point sequence as line breaks. This comprehensive set accommodates historical conventions and modern Unicode standards for handling text line divisions.
splitlines()method recognizes ten distinct code points and one multi-code-point sequence as line breaks. This comprehensive set accommodates historical conventions and modern Unicode standards for handling text line divisions.