I have a file with end-of-lines characters like \\r\\r\\n. With this, it works like I want:
\\r\\r\\n
with open(\'test.txt\', \'wb\') as f: f.write(b\'