Re: CSV Dictionary

2014-12-29 Thread Tim Chase
On 2014-12-29 16:37, JC wrote: > On Mon, 29 Dec 2014 10:32:03 -0600, Skip Montanaro wrote: > > > On Mon, Dec 29, 2014 at 10:11 AM, JC > > wrote: > >> Do I have to open the file again to get 'rdr' work again? > > > > Yes, but if you want the number of records, just operate on the > > rows list, e

Re: CSV Dictionary

2014-12-29 Thread Tim Chase
On 2014-12-29 16:11, JC wrote: > On Mon, 29 Dec 2014 09:47:23 -0600, Skip Montanaro wrote: > > > On Mon, Dec 29, 2014 at 9:35 AM, JC wrote: > >> How could I get the all the records? > > > > This should work: > > > > with open('x.csv','rb') as f: > > rdr = csv.DictReader(f,delimiter=',') > >

Re: CSV Dictionary

2014-12-29 Thread JC
On Mon, 29 Dec 2014 10:32:03 -0600, Skip Montanaro wrote: > On Mon, Dec 29, 2014 at 10:11 AM, JC wrote: >> Do I have to open the file again to get 'rdr' work again? > > Yes, but if you want the number of records, just operate on the rows > list, e.g. len(rows). > > Skip Yes, I did that. But if

Re: CSV Dictionary

2014-12-29 Thread Skip Montanaro
On Mon, Dec 29, 2014 at 10:11 AM, JC wrote: > Do I have to open the file again to get 'rdr' work again? Yes, but if you want the number of records, just operate on the rows list, e.g. len(rows). Skip -- https://mail.python.org/mailman/listinfo/python-list

Re: CSV Dictionary

2014-12-29 Thread JC
On Mon, 29 Dec 2014 09:47:23 -0600, Skip Montanaro wrote: > On Mon, Dec 29, 2014 at 9:35 AM, JC wrote: >> How could I get the all the records? > > This should work: > > with open('x.csv','rb') as f: > rdr = csv.DictReader(f,delimiter=',') > rows = list(rdr) > > You will be left with a

Re: CSV Dictionary

2014-12-29 Thread Skip Montanaro
On Mon, Dec 29, 2014 at 9:35 AM, JC wrote: > How could I get the all the records? This should work: with open('x.csv','rb') as f: rdr = csv.DictReader(f,delimiter=',') rows = list(rdr) You will be left with a list of dictionaries, one dict per row, keyed by the values in the first row:

CSV Dictionary

2014-12-29 Thread JC
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 r