Add newline to string, cross-platform Add newline to string, cross-platform linux linux

Add newline to string, cross-platform


You can try with this:

import osprint(os.linesep)


I've always just used the newline character '\n' to signify a linebreak, although windows uses a newline and a carriage return character, I tested on my windows machine (python 3.4) building a string in memory and then writing it to file, while in memory it stays as a single character ('\n') however when written to file it gets converted into two characters to have the correct line ending on windows.
up till now I have yet to come across a single library that had an issue with this.


Python uses \n to signify a line break.

Python automatically translates \n to the proper newline character based on the platform.

You can also try

import osprint (os.linesep)