CSV in Python adding an extra carriage return, on Windows

前端 未结 6 1016
慢半拍i
慢半拍i 2020-11-22 07:14
import csv
outfile = file(\'test.csv\', \'w\')
writer = csv.writer(outfile, delimiter=\',\', quoting=csv.QUOTE_MINIMAL)
writer.writerow([\'hi\',\'dude\'])
writer.wri         


        
6条回答
  •  粉色の甜心
    2020-11-22 07:46

    Note that if you use DictWriter, you will have a new line from the open function and a new line from the writerow function. You can use newline='' within the open function to remove the extra newline.

提交回复
热议问题