Fix Python – CSV in Python adding an extra carriage return, on Windows

import csv

with open(‘test.csv’, ‘w’) as outfile:
writer = csv.writer(outfile, delimiter=’,’, quoting=csv.QUOTE_MINIMAL)
writer.writerow([‘hi’, ‘dude’])
writer.writerow([‘hi2’, ‘dude2’])

The above code generates a file, test.csv, with an extra \r at each row, like so:
hi,dude\r\r\nhi2,dude2\r\r\n

instead of the expected
hi,dude\r\nh….