How to convert csv to json in python?

前端 未结 5 886
走了就别回头了
走了就别回头了 2020-12-15 22:47

I\'m very new to programming, have been learning python from past 3/4 weeks and this is one of the assignments given.

Input



        
5条回答
  •  有刺的猬
    2020-12-15 23:20

    Dump after processing whole rows.


    import csv
    import json
    
    with open('test.csv') as f:
        reader = csv.DictReader(f)
        rows = list(reader)
    
    with open('test.json', 'w') as f:
        json.dump(rows, f)
    

提交回复
热议问题