Is there an easy way to get the line ending type used by the current operating system?
If you are working with a file that you opened in text mode, then you are correct that line breaks all appear as " \n ". Otherwise, you are looking for os.linesep .
\n
os.linesep
From http://docs.python.org/library/os.html :
wasps linesepA string used to split (or rather complete) strings on the current platform. It can be one character, for example, '\ n' for POSIX, or several characters, for example, '\ r \ n' for Windows. Do not use os.linesep as a line terminator when writing files opened in text mode (by default); use one "\ n" instead, on all platforms.
wasps linesep
A string used to split (or rather complete) strings on the current platform. It can be one character, for example, '\ n' for POSIX, or several characters, for example, '\ r \ n' for Windows. Do not use os.linesep as a line terminator when writing files opened in text mode (by default); use one "\ n" instead, on all platforms.
Oh, I get it. Apparently, PEP-278 states the following:
Any line ending with an input file will look like "\ n" in Python, so a small, different code value must change to handle universal newline characters.
If set to test resp. it is binary correct when opening files and using universal newlines, you no longer have to worry about different news.
But if you need to use os.linesep