splitlines() and iterating over an opened file give different results
问题 I have files with sometimes weird end-of-lines characters like \r\r\n . With this, it works like I want: with open('test.txt', 'wb') as f: # simulate a file with weird end-of-lines f.write(b'abc\r\r\ndef') with open('test.txt', 'rb') as f: for l in f: print(l) # b'abc\r\r\n' # b'def' I want to able to get the same result from a string . I thought about splitlines but it does not give the same result: print(b'abc\r\r\ndef'.splitlines()) # [b'abc', b'', b'def'] Even with keepends=True , it's