python - How to print the number of columns and lines in a csv file? -


i python newbie might sound silly question, have csv file , want script print number of lines , number of columns in file. script:

import csv  op = open(test06242015.csv) rd = csv.reader(op)   row in rd:     list = []     list.append(row)     print list     items in row:         print len(row)  op.close() 

i getting right answer (320), prints out 320 times each row (below):

[['19.385', '19.227', '18.308', ...]] 320 320 320 320 320 320 320 320 (...and keeps going) 

how can make 320 prints out once? also, how can read number of rows well?

thanks lot!

you printing length of row inside inner loop, try printing outside inner loop.

example -

for row in rd:     list = []     list.append(row)     print list     items in row:         pass # or whatever other logic want, if not want remove loop     print len(row) 

Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -