Need function to test if EFFECTIVE UID has read-access to a file.

Mike Meyer mwm at
Thu Nov 18 20:46:28 CET 2004

NutJob at (Markus Kemp) writes:

> Hi Skip,
> Skip Montanaro <skip at> wrote in message news:<mailman.6498.1100715267.5135.python-list at>...
>> try:
>>     f = open("somefile")
>> except IOError:
>>     print "file not readable"
> Ow, is that the only way? =( Because as I see it, open() is a
> relatively costly function compared to something like os.access()

Yeah. you can improve on this by using That way you won't
have the overhead of creating a Python file object.

However, both access and open will have to read status information
from the disk to do their job. The I/O involved should swamp any
difference in computation between the two.

Of course, the right thing to do is time them.

BTW, should work on a directory.

Mike Meyer <mwm at>
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.

More information about the Python-list mailing list