I am generating some text in my application. Since the text is part of a bigger message, sometimes I need to add newlines, sometimes not:
NEWLINE = '\n' # TODO: how to define this cross-platform? Can I use os.linesep?
txt = 'Hello'
txt += NEWLINE
msg = get_txt(True)
msg += get_txt(True)
msg += get_txt(False)
Hello (no newline here)
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.