Python csv的writerow()和writerows()区别

import csv

writerow()

writerow()将一个列表全部写入csv的同一行。

	csv_list = [1234]
    with open("/Users/apple/Downloads/test.csv","w",encoding="UTF-8",newline="") as csvfile:
        writer = csv.writer(csvfile)
        writer.writerow(csv_list)

结果:
同

writerows()

writerows()将一个二维列表中的每一个列表写为一行。

	csv_list = [[1],[2],[3],[4]]
    with open("/Users/apple/Downloads/test.csv","w",encoding="UTF-8",newline="") as csvfile:
        writer = csv.writer(csvfile)
        writer.writerows(csv_list)

结果:
Python csv的writerow()和writerows()区别_第1张图片

你可能感兴趣的:(笔记,csv,python,列表)