Windows:
Uses CR (\r) in combination with LF (\n) for line endings, facilitating compatibility with legacy systems.
Unix-like systems (including Linux and macOS):
Employs LF (\n) for line endings, offering simplicity and compatibility with text processing utilities.
Older Macintosh systems:
Uses CR (\r) for line endings in some file formats, retaining compatibility with legacy systems.
Question:
When I write the following in Notepad++ on Windows with all symbols displayed, I get this:
But when I write a simple code in Python also on Windows, I get this in the terminal:
print('Hello \nWorld')
It seems that Windows uses the CR LF
as a convention for every new line, but why does Python compile without the CR if I only write \n
and not \r\n
as an equivalent to CR LF
?
1 Answer 1
Windows uses CR (\r) in combination with LF (\n) for line endings, facilitating compatibility with legacy systems.
Well, no. A windows system stores text files on the hard drive with whatever style of line endings you gave them.
If you follow the windows convention most windows programs that read these files will interpret the line endings correctly.
Some, like python interpreters, notepad++, and eclipse will interpret the line endings correctly whichever convention the file follows.
Others won’t. It’s not the file system that makes the difference here. Or the operating system. It’s whatever’s reading and saving the file. It’s only a windows thing because one style is most popular in windows.
-
1Plus for NP++ and most text editors you can just change which kinds of newlines are savedinaba– inaba02/19/2024 12:53:06Commented Feb 19, 2024 at 12:53
os.linesep