[Tutor] how to know if a file exists

Vikram Shenoy vikramumanathshenoy at gmail.com
Thu Jan 4 10:15:25 CET 2007


Hi,

import os

if os.path.exists('/path/to/file'):
     # File exists
else:
     # File doesn't exist

It works for files as well as directories.

Regards,
Vikram U Shenoy
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070104/ae5963c9/attachment.htm 


More information about the Tutor mailing list