Detect file existance before open?

Gordon McMillan gmcm at hypernet.com
Sat Oct 16 23:39:40 EDT 1999


greg andruk wrote:
> In nnmh:python, Bill Rodgers <Bill at nospam.com> wrote:
> 
> > 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.
> 
> os.stat() will do the job.

>>> os.stat('kablooie')
Traceback (innermost last):
  File "<interactive input>", line 1, in ?
OSError: [Errno 2] No such file or directory: 'kablooie'
>>> 

- Gordon




More information about the Python-list mailing list