I've seen these in documentation, namely in the "importlib" documentation for Python 3.1, and I'm wondering what the difference is between a "universal newline" and a "standard newline", if any.

I know it has to do with the byte sequence that is used to represent newlines, and I think universal newlines are simply a single linefeed byte, but I'm not sure about standard newlines. Are they simply the form the host machine uses?

Edited by lrh9: n/a

8 Years
Discussion Span
Last Post by HiHe

Unix/Linux uses '\n'
Windows uses '\r\n'
Mac uses '\r'
for newlines, which manifest themselves in documents/text written on these machines.

Python by default uses "Universal Newline" support which translates all of the different newlines to '\n' when you open a document/text file.

As to "Standard Newline", there is no agreed to standard!


Then the documentation is wrong.

I did learn that the exec function will only take source that uses '\n' to represent newlines.

I also learned that byte data (and string data) has a replace method that can replace each instance of a byte sequence (or string) with another byte sequence (or string).

Your information led me to realize that you can't manually replace all instances of a specific byte sequence, because different operating systems use different byte sequences to represent newlines. Is there a variable defined in a module that represents the system's newline bytes?


There is a variable in the os module called linesep that represents the line separator in text files.

In order to get the bytes for the linesep all you have to do is "os.linesep.encode()".


I understand that the "\r\n" or "\n\r" combination goes back to the old mechanical printers where you had to feed the paper up one line and set the carriage to the beginning margin. I guess this was the standard then.

Edited by HiHe: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.