There may be several ways to check whether or not a file exists. You can try one of the following two methods:
Method 1:
try: fh = open('/path/to/your/file' , 'r')except: fh = Noneif (fh is not None): #perform operations on your fileelse: print ('File does not exist')
Method 2:
import osif (os.path.isfile('/path/to/your/file')): #perform operations on your fileelse: print ('File does not exist')