Python get proper line ending

If you are operating on a file that you opened in text mode, then you are correct that line breaks all show up as ‘\n‘. Otherwise, you are looking for os.linesep . From http://docs.python.org/library/os.html: os.linesep The string used to separate (or, rather, terminate) lines on the current platform. This may be a single character, such … Read more

Convert ^M (Windows) line breaks to normal line breaks

Command :%s/<Ctrl-V><Ctrl-M>/\r/g Where <Ctrl-V><Ctrl-M> means type Ctrl+V then Ctrl+M. Explanation :%s substitute, % = all lines <Ctrl-V><Ctrl-M> ^M characters (the Ctrl-V is a Vim way of writing the Ctrl ^ character and Ctrl-M writes the M after the regular expression, resulting to ^M special character) /\r/ with new line (\r) g And do it globally … Read more

Historical reason behind different line ending at different platforms

DOS inherited CR-LF line endings (what you’re calling \r\n, just making the ascii characters explicit) from CP/M. CP/M inherited it from the various DEC operating systems which influenced CP/M designer Gary Kildall. CR-LF was used so that the teletype machines would return the print head to the left margin (CR = carriage return), and then … Read more