You could try this (safer):
try: # http://effbot.org/zone/python-with-statement.htm # 'with' is safer to open a file with open('whatever.txt') as fh: # Do something with 'fh'except IOError as e: print("({})".format(e))
The ouput would be:
([Errno 2] No such file or directory:'whatever.txt')
Then, depending on the result, your program can just keep running from there or you can code to stop it if you want.