In Python 2.X, it was required to open csvfile with 'b' because the csv module does its string completion processing.
In Python 3.X, the csv module still does its own string termination processing, but still needs to know the encoding for Unicode strings. The correct way to open a csv file for writing is:
outputfile=open("out.csv",'w',encoding='utf8',newline='')
encoding can be anything you need, but newline='' suppresses newline='' processing in text mode. On Windows, this will not write the line endings of the file \ r \ r \ n instead of the correct \ r \ n. This is only mentioned in the 3.X documentation of csv.reader , but csv.writer also requires it.
source share