best way of testing a program exists before using it?

skip at pobox.com skip at pobox.com
Tue Sep 12 17:03:41 CEST 2006


    Nick> Tim Golden <tim.golden at viacom-outdoor.co.uk> wrote:
    >> [Nick Craig-Wood]
    >> 
    >> | Tim Golden <tim.golden at viacom-outdoor.co.uk> wrote:
    >> | >          if os.path.isfile (filepath):
    >> | >            print filepath
    >> | 
    >> | You might get a more accurate result using
    >> | 
    >> |   os.access(filepath, os.X_OK)
    >> | 
    >> | instead of
    >> | 
    >> |   os.path.isfile(filepath)
    >> | 
    >> | Which checks the file is executable

Just picking up this thread late.  Note that access() doesn't do what you
want unless your real and effective user ids are the same.  Granted, that's
the case most of the time, but not always...

Skip



More information about the Python-list mailing list