fsock = open("notthere.txt", "r") try: fsock = open("notthere.txt") except IOError: print "The file does not exist, exiting gracefully" print "This line will always print"