Python docs specifies:
The reader is hard-coded to recognise either '\r' or '\n' as end-of-line, and ignores lineterminator. This behavior may change in the future.
I wrote a simple program
step 1
with open('test.csv','wb') as f:
f.write(b'hello\r\rworld\n!')
step 2
import csv
with open('test.csv','r',newline='') as f:
r = csv.reader(f)
for row in r:
print(row)
Output of step 2:
['hello']
[]
['world']
['!']
If I change step 1 to :
import csv
with open('test.csv','wb') as f:
f.write(b'hello\r\nworld\n!')
Output:
['hello']
['world']
['!']
My question is why the empty list [] disappeared in this case?
If I am correct then in step 2 csv.reader encountered first \r and returned what it had read until then, but when it encountered second \r immediately after first, it had not read anything and hence returned empty list.
But why this doesn't happen in second case if \n is also end-of-line for csv.reader?