Need function to test if EFFECTIVE UID has read-access to a file.
Mike Meyer
mwm at mired.org
Thu Nov 18 14:46:28 EST 2004
NutJob at gmx.net (Markus Kemp) writes:
> Hi Skip,
>
> Skip Montanaro <skip at pobox.com> wrote in message news:<mailman.6498.1100715267.5135.python-list at python.org>...
>> 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 os.open. 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, os.open should work on a directory.
<mike
--
Mike Meyer <mwm at mired.org> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
More information about the Python-list
mailing list