Creating a dictionary from a csv file?

后端 未结 16 2266
北荒
北荒 2020-11-22 06:13

I am trying to create a dictionary from a csv file. The first column of the csv file contains unique keys and the second column contains values. Each row of the csv file rep

16条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-22 06:20

    You can use this, it is pretty cool:

    import dataconverters.commas as commas
    filename = 'test.csv'
    with open(filename) as f:
          records, metadata = commas.parse(f)
          for row in records:
                print 'this is row in dictionary:'+rowenter code here
    

提交回复
热议问题