Detect existing files?
Brian Quinlan
BrianQ at ActiveState.com
Wed May 2 12:57:09 EDT 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