Detect file existance before open?

Gordon McMillan gmcm at hypernet.com
Sat Oct 16 23:21:43 EDT 1999


Bill Rodgers asks:

> I would like to check for the existance of a file before I
> attempt an open and maybe throw an exception.  I don't see a way
> to do this.  I would like to tell the user that the file he
> specified doesn't exist.  Is there a way to do this or do I need
> to catch the exception and deal with it that way?

os.path.exists(nm), probably also os.path.isfile(nm).

Of course, the fact that it exists and is a file still doesn't mean 
the user can open it.


- Gordon




More information about the Python-list mailing list