[Tutor] try and file existence

Clayton Kirkwood crk at godblessthe.us
Sat Aug 15 03:28:09 CEST 2015

    fp = open( user_preferences )
except( PermissionError ):
    with open(user_preferences ) as f:

I originally only had the bottom open statement. Ran but file didn't exist,
and my run failed with file doesn't exist. I figured I'd check to see if the
file existed. This is one of those situations where a search of
documentation for fd_exist (which I thought I'd seen once), or exist turns
up either nothing or nothing relevant. I finally found that the try: clause
with the open statement might help and I copied the snippet to my code. I am
getting an indentation error: expected an indent block. What is wrong, and
what is the best way to find out if a file exists?



More information about the Tutor mailing list