Answers for "filenotfounderror python try catch'"

0

python file open try except error

def FileCheck(fn):
    try:
      open(fn, "r")
      return 1
    except IOError:
      print "Error: File does not appear to exist."
      return 0

result = FileCheck("testfile")
print result
Posted by: Guest on July-02-2020
0

except FileNotFoundError

# FileNotFoundError is a subclass of OSError, catch that or the exception itself:
except OSError as e:
Posted by: Guest on October-28-2021

Python Answers by Framework

Browse Popular Code Answers by Language