File ExistsThe fileExists() method will attempt to open a file for reading. If it exists, a True value will be returned from the method. If the file does not exist, a False value is returned. A string containing the file name must be passed to the method.
def fileExists (fname): f_exists = False try: f=open(fname,'r') f.close() f_exists = True except: print("file '"+ fname+ "' does not exist")
return f_exists |
|