第1个回答 2018-06-12
实测是可以从 a.csv复制到 b.csv中
import csv
def foo():
with open('a.csv', 'r') as f:
reader = csv.DictReader(f)
rows = [row for row in reader]
if not rows:
return
with open('b.csv', mode='w', newline='', errors='ignore') as f2:
for index, row in enumerate(rows):
if index == 0:
f_csv = csv.DictWriter(f2, fieldnames=list(row.keys()))
f_csv.writeheader()
f_csv.writerow(row)
if __name__ == '__main__':
foo()本回答被提问者和网友采纳