I am having difficulties with raising exceptions, for example:
import csv
o = open('/home/foo/dummy.csv', 'r') # Empty file!
reader = csv.reader(o, delimiter=';')
reader = list(reader)
try:
for line in reader:
print line[999] # Should raise index out of range!
except Exception, e:
print e
Basically csv.reader reads empty file, is converted to an empty list, and code above should print IndexError. But it does not. Code below however raises perfectly:
print reader[0][999]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IndexError: list index out of range
Am I doing something wrong?