import csv
with open(\'thefile.csv\', \'rb\') as f:
data = list(csv.reader(f))
import collections
counter = collections.defaultdict(int)
for row in data:
The simple answer is that csv files should always be opened in binary mode whether for input or output, as otherwise on Windows there are problems with the line ending. Specifically on output the csv module will write \r\n
(the standard CSV row terminator) and then (in text mode) the runtime will replace the \n
by \r\n
(the Windows standard line terminator) giving a result of \r\r\n
.
Fiddling with the lineterminator
is NOT the solution.