Answers for "try except open file python"

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

python open file exception

try:
  with open("path\to\file", "r"):
    ...
except FileNotFoundError:
  print("file does not exist :(")
Posted by: Guest on September-12-2021
0

try open file

try:
    with open("file.txt","r") as f:
        #stuff goes here
except IOError:
    #do what you want if there is an error with the file opening
Posted by: Guest on October-02-2021

Python Answers by Framework

Browse Popular Code Answers by Language