[Tutor] Checking for the existence of a file

Drew Perttula drewp@bigasterisk.com
Tue Jan 21 14:49:05 2003


> script.  The current method I use is:
> 
> if os.popen('ls '+filename).read()[:-1]==filename:
> 	exists=1
> else:
> 	exists=0

Yikes! :)

Check out os.path.exists (and also os.listdir for other directory
listing needs).

-Drew