Detect existing files?

Brian Quinlan BrianQ at
Wed May 2 18:57:09 CEST 2001

Stephan Schulz wrote:
> Now my question: Is there a simple way to detect an existing file?
> open() seems to raise an error if the file does not exist, which is
> kind of overkill for me.

Take a glance at os.access(). Simple usage:

import os
os.access( r'c:\test.txt', os.F_OK )

But if I needed to access the file anyway, I would just use open() and
handle the exception.

More information about the Python-list mailing list