I am trying to use the fileinput.input() module to read in the lines from a bunch of files in a directory and occasionally receive an IOerror exception. What is the best way to handle this exception so that if 1 of the items in the list i'm feeding fileinput,input() generates this IOError, i can get fileinput to simply continue onto the next item in the list ?
for line in fileinput.input(newlist):
num_matches = string.count(line, searchterm)
if num_matches: # a nonzero count means there was a match
print "found '%s' %d times in %s on line %d." % (searchterm, num_matches,
print "There was a problem with at least 1 of the matches"