[Tutor] os.access unreliable?

Tim Golden mail at timgolden.me.uk
Wed Aug 25 10:53:08 CEST 2010

On 25/08/2010 09:28, Albert-Jan Roskam wrote:
> Hi,
> Hi I'm using os.access to do a preliminary check to see if I have RW access, but
> it seems to be unreliable. In a dir for which I have only read access, os.access
> also says I have write access. This is under Windows 2000. I could of course use
> a try-except and catch the IOError, but I'd like to know why the code below
> isn;t working.
>      def isAcccessible(self):
>          if os.access(self.path, os.R_OK) and os.access(self.path, os.W_OK):
>              return True
>          else:
>              return False

os.access is effectively meaningless under Windows, especially
against directories. It only checks the read-only flag (which
doesn't mean anything for directories anyway).

There is a long-open issue here:


which I am half-minded to close although I could be
persuaded to pursue it if anyone were interested enough.
On the other hand, os.access checks are open to race-conditions
in any case, so you might simply be better off with a
try-except block as you suggest.

If you want more information I can explain further but unless you
want to dive into the Windows API and use AccessCheck -- which is
what that patch is doing -- then I suggest you use try-except


More information about the Tutor mailing list