how do i check if a file exists with python?

Daniel Klein DanielK at aracnet.com
Fri Dec 29 05:25:31 CET 2000


How about something like

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


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

Dan



"Scott Hathaway" <slhath at home.com> wrote in message
news:RlM26.98766$yR4.2639444 at news1.rdc1.tx.home.com...
> I have searched Deja, looked in two pyton books, and searched the
python.org
> 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