best way of testing a program exists before using it?

Tim Golden tim.golden at viacom-outdoor.co.uk
Tue Sep 12 10:48:04 EDT 2006


| 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
| > 
| >  Sadly, not under Win32, hence the shenanigans with
| >  the PATHEXT variable :)

[Nick Craig-Wood]
| Make a patch for os.access()?  It says in the docs it works on
| Windows!

I suspect it might end up being a doc patch. AFAICR the os-specific 
stuff is implemented in C; I'll try downloading the source at some 
point and having a look.

The existing docs do say, though:

"""
Note: I/O operations may fail even when access() indicates that 
they would succeed, particularly for operations on network filesystems 
which may have permissions semantics beyond the usual POSIX
permission-bit model. 
"""

Don't know if this covers the case meanwhile.

TJG

________________________________________________________________________
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:
http://www.star.net.uk
________________________________________________________________________



More information about the Python-list mailing list