with open(fileName,'w',newline='') as f: self.fileNames = ['timestamp','elapsedtime'] writer = csv.DictWriter(f,fieldnames = self.fileNames) for li in self.allData: #分行读取 writer.writerow({'timestamp':li[0],'elapsedtime':li[1]})#以字典格式写入