I am using Python 3.6.3 on Windows. When I try to print a single multiline string to file like this:
with open('test1.txt', mode='w') as f:
f.write('test\r\ntest\r\n')
Then test1.txt will end up containing test\r\r\ntest\r\r\n instead of test\r\ntest\r\n.
A workaround to get the desired output would look like so:
with open('test2.txt', mode='w') as f:
for line in 'test\r\ntest\r\n'.splitlines():
print(line, file=f)
Why is this happening?