HiHe function is ok,but some changes that i think make it better.
Bare except(catch all maybe) i dont like this to much.
And with open()
is preferred over open()
,no need to close file object and it dos some error checking to.
def file_exists(filename):
try:
with open(filename) as f:
return True
except IOError:
return False
Or return the specific error masseage to user.
def file_exists(filename):
try:
with open(filename) as f:
return True
except IOError as error:
return 'A problem occurred: {}'.format(error)