[EMAIL PROTECTED] | Sent: 12 September 2006 16:04 | To: python-list@python.org | Subject: Re: best way of testing a program exists before using it? | | Nick> Tim Golden <[EMAIL PROTECTED]> wrote: | >> [Nick Craig-Wood] | >> | >> | Tim Golden <[EMAIL PROTECTED]> 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: http://msdn2.microsoft.com/en-us/library/1w06ktdy.aspx 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? 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 ________________________________________________________________________ -- http://mail.python.org/mailman/listinfo/python-list