I commonly use os.path.exists()
to check if a file is there before doing anything with it.
I\'ve run across a situation where I\'m calling a executable that
You could get the PATH environment variable, and try "exists()" for the .exe in each dir in the path. But that could perform horribly.
example for finding notepad.exe:
import os
for p in os.environ["PATH"].split(os.pathsep):
print os.path.exists(os.path.join(p, 'notepad.exe'))
more clever example:
if not any([os.path.exists(os.path.join(p, executable) for p in os.environ["PATH"].split(os.pathsep)]):
print "can't find %s" % executable
Is there a specific reason you want to avoid exception? (besides dogma?)