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.