best way of testing a program exists before using it?

Tim Golden tim.golden at
Tue Sep 12 17:11:00 CEST 2006

[skip at]
| Sent: 12 September 2006 16:04
| To: python-list at
| Subject: Re: best way of testing a program exists before using it?
|     Nick> Tim Golden <tim.golden at> wrote:
|     >> [Nick Craig-Wood]
|     >> 
|     >> | Tim Golden <tim.golden at> 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...

Also, I just looked at the implementation in posixmodule.c,
and at the msdn article on its use, and at a thread in python-dev
a year or so ago. The last -- where someone was proposing more
specifics if the call fails -- didn't really go anywhere, and is
full of people (GvR and others) saying: don't use os.access unless...

The msdn article:
doesn't even seem to suggest that checking for executableness is a
possibility, and I think that the posixmodule.c code is simply
swallowing any non-OK return value and saying: No. (The msdn page
suggests that invalid parameters will return EINVAL).

All that said, I think the only thing would be to add a line to
the docs saying sthg like: This will always return False for X_OK under
Win32. I'm happy to submit the patch, but is it worth it?


This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:

More information about the Python-list mailing list