how do i check if a file exists with python?

Daniel Klein DanielK at
Thu Dec 28 23:25:31 EST 2000

How about something like

def fileExists(f):
        file = open(f)
    except IOError:
        exists = 0
        exists = 1
    return exists

Although this is not as elegant as the person who submitted the 'glob'


"Scott Hathaway" <slhath at> wrote in message
news:RlM26.98766$yR4.2639444 at
> I have searched Deja, looked in two pyton books, and searched the
> site trying to find out this simple question.
> Can someone please give me the call and the module it lives in?
> Thanks,
> Scott

More information about the Python-list mailing list