writeheader()因为您使用附加选项打开文件。
像这样:
import os.pathfile_exists = os.path.isfile(filename)with open (filename, 'a') as csvfile: headers = ['TimeStamp', 'light', 'Proximity'] writer = csv.DictWriter(csvfile, delimiter=',', lineterminator='n',fieldnames=headers) if not file_exists: writer.writeheader() # file doesn't exist yet, write a header writer.writerow({'TimeStamp': dic['ts'], 'light': dic['light'], 'Proximity': dic['prox']})
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)