[Python-Dev] os.access on Windows

Tim Golden mail at timgolden.me.uk
Mon May 23 10:42:38 CEST 2011

On 20/05/2011 22:56, "Martin v. Löwis" wrote:
>> TBH I think the less attractive we can make os.access() look the
>> better. It uses the real uid instead of the effective uid, it
>> encourages LBYL behavior, the outcome may be incorrect, it doesn't
>> work on Windows... The ONLY reason to ever use it is in a setuid()
>> program. But who writes those any more? (Esp. in Python!)
> +1. The best way to determine "could I access this file" is to try
> to access it, and be prepared to get an exception.

FWIW the OP knew this but -- for some reason specific to his
use case -- wanted to avoid updating the mod dates of the containing
directory. Obviously that's his problem, not ours...

 > So we might deprecate-then-delete it on Windows.

I'll rework that patch to be a DeprecationWarning in that case.

> People who *really* need to know in advance should use the Windows
> API for that on Windows (i.e. call AccessCheck).

And indeed this is what I've recommended to the OP. I'll follow this
up in that python-list thread. I see that Benjamin's updated the
os.access docs so I'll let this thread die and talk the OP through
the AccessCheck route (which is, unfortunately, more tricky because
it's not exposed by pywin32. Also not our problem...)


More information about the Python-Dev mailing list