try: fin = open("data.txt") ...continue reading file fin.close() except: ...do something else