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
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
try catch python with open
import os ,csv
# Created to ensure file/dataset are being load properly
# Place below your filename with .csv where 'x' is .
data = open('x', 'r')
while True:
try:
if data == open('x'):
print('file is open')
except IOError:
print('Unable to load files')
break
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us