I have the python script written as :
import csv
with open ("ann.csv", "r") as csvfile:
reader = csv.reader(csvfile)
collected = []
for row in reader:
collected.append(row[0])
print (",".join(collected))
ann.csv file as :
colums_header
7432
7849
7844
7108
8712
7833
7842
8723
7895
8719
9899
7352
7515
7252
8906
continued
When I try to run the python script it gives error :
Traceback (most recent call last):
File "columnTorow.py", line 6, in <module>
collected.append(row[0])
IndexError: list index out of range
Why am I getting the out of range exception?
','.join(row[0] for row in reader)- if you have empty lines you could provide a guard, e.g.','.join(row[0] for row in reader if row)rowvalue insideforloop, I think some where in input file empty row is present. Problem in input csv, not in python code.