# L-28 MCS 260 Wed 31 Oct 2007 : readfilename3.py # # Prompts the user for a file name and displays # an error message if the name given by the user # does not correspond to a file. class FileNotThere(IOError): """ The exception FileNotThere is raised when a file does not exist. The argument of the exception is the file name. """ def __init__(self,name=''): self.name = name name = raw_input('Give the name of a file : ') try: try: file = open(name,'r') except IOError: raise FileNotThere(name) except FileNotThere,e: print 'file ' + e.name + ' does not exist'