CSV in Python adding an extra carriage return, on Windows

前端 未结 6 1015
慢半拍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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-22 07:54

    You have to add attribute newline="\n" to open function like this:

    with open('file.csv','w',newline="\n") as out:
        csv_out = csv.writer(out, delimiter =';')
    

提交回复
热议问题