This is the simplest way to check if a file exists. Just because the file existed when you checked doesn't guarantee that it will be there when you need to open it.
import osfname = "foo.txt"if os.path.isfile(fname): print("file does exist at this time")else: print("no such file exists at this time")