【发布时间】:2016-04-19 12:20:13
【问题描述】:
我需要帮助,我不想打印 CSV 文件的标题。
csvfile = open('testdata.csv', 'rU')
jsonfile = open('brofile.json', 'w')
fieldnames = {'Matric':[("studentName","dept","status")]}
reader = csv.DictReader( csvfile, fieldnames)
for row in reader:
json.dump(row, jsonfile)
jsonfile.write('\n')
预期输出
[2010CS01: { "Jones Doe", "Computer science", "paid"}]
[2010CS02: {"James Rug", "Computer Science", "Paid"}]
[2010AC01: {"Curtis Payne", "Accounting", "unpaid"}]
CSV 文件:
Matric Name Department Status
2010CS01 Jones Doe Computer Science Paid
2010CS02 James Rug Computer Science Paid
2010AC01 Curtis Payne Accounting Unpaid
【问题讨论】:
-
我投票结束这个问题作为题外话,因为 SO 不是代码编写服务
-
然后?你试过什么?
-
预期的输出不是有效的 JSON。