Re: Number of cells, using CSV module

2013-05-16 Thread tunacubes
Thank you Skip, worked great. And thank you Tim for Tidying things up! -- http://mail.python.org/mailman/listinfo/python-list

Re: Number of cells, using CSV module

2013-05-16 Thread Tim Chase
On 2013-05-16 14:08, Skip Montanaro wrote: > > So rather than > >>a > >>b > >>c > >>d > >>e > >>f > > I would get [a, b, c, d, e, f] > > all_items = [] > for row in reader: > all_items.append(row[0]) And following up here, this could be tidily rewritten as all_items = [row[0] for row in re

Re: Number of cells, using CSV module

2013-05-16 Thread Tim Chase
On 2013-05-16 14:07, Skip Montanaro wrote: > > len(reader) gives me an error. > > Apologies. len(list(reader)) should work. Of course, you'll wind > up loading the entire CSV file into memory. You might want to just > count row-by-row: > > n = 0 > for row in reader: > n += 1 which can nic

Re: Number of cells, using CSV module

2013-05-16 Thread Skip Montanaro
> So rather than >>a >>b >>c >>d >>e >>f > I would get [a, b, c, d, e, f] all_items = [] for row in reader: all_items.append(row[0]) Skip -- http://mail.python.org/mailman/listinfo/python-list

Re: Number of cells, using CSV module

2013-05-16 Thread Skip Montanaro
> len(reader) gives me an error. Apologies. len(list(reader)) should work. Of course, you'll wind up loading the entire CSV file into memory. You might want to just count row-by-row: n = 0 for row in reader: n += 1 Skip -- http://mail.python.org/mailman/listinfo/python-list

Re: Number of cells, using CSV module

2013-05-16 Thread tunacubes
I guess another way to accomplish this would be, is there any way that I can turn the returned value for (column) into 1 list? So rather than >a >b >c >d >e >f I would get [a, b, c, d, e, f] -- http://mail.python.org/mailman/listinfo/python-list

Re: Number of cells, using CSV module

2013-05-16 Thread tunacubes
On Thursday, May 16, 2013 2:40:08 PM UTC-4, Skip Montanaro wrote: > Perhaps you want len(reader) instead?  Or a counter which increments for > every row read which has an item in column A? > > > > Skip len(reader) gives me an error. I tried a counter, but unfortunately due to the simplicity

Re: Number of cells, using CSV module

2013-05-16 Thread Skip Montanaro
Perhaps you want len(reader) instead? Or a counter which increments for every row read which has an item in column A? Skip -- http://mail.python.org/mailman/listinfo/python-list

Number of cells, using CSV module

2013-05-16 Thread tunacubes
I'm using the csv module to get information from a csv file. I have items listed in Column A. I want to know how many items are listed in Column A. import csv with open('test.csv', 'r') as f: reader = csv.reader(f) for column in reader: column = (column[0]) print(column)