You can also track an inappropriate line without affecting the flow / error free
file = open("sms.txt", "r") for line_no,line in enumerate(file): a=word_tokenize(line) try: if a[5] == 'SBI' and a[6]== 'Debit': print a[13] except IndexError: print str(line_no)+" line doesn't have expected data" continue
source share