I am new to python but have experience with C/sh/java.. My first homework is csv field replacement, if field has specific value
My csv file has 24 columns and has ~ as field seperator. I want to change field 24th with T if it's True My code is like that
import csv
with open ('MyCustomerList.csv', 'r', encoding='utf-8' ) as fi:
reader = csv.reader (fi, delimiter = '~')
for row in reader:
if row[23] == 'True':
print (row[23])
But it gives an error like that
C:\>c:\Python34\python.exe pyt1.py
Traceback (most recent call last):
File "pyt1.py", line 5, in <module>
if row[23] == 'True':
IndexError: list index out of range
I could not figured out the issue what is the error ?
try/exceptand handle the issue as necessary (abort, ignore, substitute, etc) in theexceptclause.