import csv
# 打开文件,没有文件自动创建一个csv文件
csv_file = open('demo.csv','w',newline='',encoding='utf-8')
# 将文件赋值给新参数
writer = csv.writer(csv_file)
# 写入数据 单行写入
writer.writerow(['a1','a2','a3'])
# 写入数据 多行写入
writer.writerows(['black','white'],['big','small'],['love','hate'])
# 写入结束保存关闭
csv_file.close()
# 读取csv文件
csv_file1 = open('demo.csv','r',newline='',encoding='utf-8')
reader = csv.reader(csv_file1)
for row in reader:
print(row)