Hello,

I have csv file like:

id,name,userid,password
1,ABC,def@ghi,1234
2,DEF,ghi@jkl,asdf
3,GHI,jkl@mno,zxcv
.
.
.

I need to get that csv file into a dictionary. Here is my code:

import csv

with open('x.csv','rb') as f:
    rdr = csv.DictReader(f,delimiter=',')
    flds = rdr.fieldnames
    rows = 0
    d = {}
    for row in rdr:
        rows += 1
        i = 0
        for i in range(len(flds)):
            d[flds[i]] = row[flds[i]]

It shows only the last record, like:
d = {'Password': 'zxcv', 'UserId': 'jkl@mno', 'id': '3', 'Name': 'GHI'}

How could I get the all the records?

Thanks.
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to