Testing for a file in python?

Thaddeus L. Olczyk olczyk at interaccess.com
Mon Jun 12 12:22:10 EDT 2000


How would you go about testing if a certain file exists in python?
In most scripting languages you have the -f test:

if -f filename do
   whatever_you_were_going_to_do
   fi
else do
   print "Error" file not found
   fi

stat doesn't work, it aborts if the file does not exist.



More information about the Python-list mailing list