List1=['a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a']
List2=['b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b', 'b']
List3=['c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c', 'c']
csvfile = open("D:/test.csv", 'w' ,encoding="UTF8",newline='')
writer=csv.writer(csvfile, delimiter=",")
writer.writerows(zip(List1,List2,List3))
csvfile.close()
参考资料如下(摘自: https://stackoverflow.com/questions/3348460/csv-file-written-with-python-has-blank-lines-between-each-row):
In Python 2, open outfile with mode ‘wb’ instead of ‘w’. The csv.writer writes \r\n into the file directly. If you don’t open the file in binary mode, it will write \r\r\n because on Windows text mode will translate each \n into \r\n.
In Python 3 the required syntax changed, so open outfile with the additional parameter newline=’’ instead.
Examples:
with open(’/pythonwork/thefile_subset11.csv’, ‘wb’) as outfile:
writer = csv.writer(outfile)
with open(’/pythonwork/thefile_subset11.csv’, ‘w’, newline=’’) as outfile:
writer = csv.writer(outfile)