标签:ext csv with last rest beans ade 属性 创建
写入内容:
class csv.DictWriter(f,fieldnames,restval =‘‘,extrasaction =‘raise‘,dialect =‘excel‘,* args,** kwds )
import csv
with open(‘names.csv‘, ‘w‘, newline=‘‘) as csvfile:
#设置需要写入的属性
fieldnames = [‘first_name‘, ‘last_name‘]
#创建DicWriter类,实例化后可写入或读取
writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
#创建实例化写入对象
writer.writeheader()
writer.writerow({‘first_name‘: ‘Baked‘, ‘last_name‘: ‘Beans‘})
writer.writerow({‘first_name‘: ‘Lovely‘, ‘last_name‘: ‘Spam‘})
writer.writerow({‘first_name‘: ‘Wonderful‘, ‘last_name‘: ‘Spam‘})
标签:ext csv with last rest beans ade 属性 创建
原文地址:https://www.cnblogs.com/7134g/p/11516892.html