To accept any of \r , \n , \r\n as a new line, you can use the file mode 'U' (universal new line):
>>> open('test_newlines.txt', 'rb').read() 'a\rb\nc\r\nd' >>> list(open('test_newlines.txt')) ['a\rb\n', 'c\r\n', 'd'] >>> list(open('test_newlines.txt', 'U')) ['a\n', 'b\n', 'c\n', 'd'] >>> open('test_newlines.txt').readlines() ['a\rb\n', 'c\r\n', 'd'] >>> open('test_newlines.txt', 'U').readlines() ['a\n', 'b\n', 'c\n', 'd'] >>> open('test_newlines.txt').read().split() ['a', 'b', 'c', 'd']
If you want to get a numerical (float) array from a file; see Reading a line of a file into an array (pythonic)
source share