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

Peter Hansen peter at engcorp.com
Thu Nov 18 15:48:13 EST 2004


Mike Meyer wrote:
> NutJob at gmx.net (Markus Kemp) writes:
>>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.

Actually, the right thing to do is to take the simplest
and cleanest approach, and only change that if you have
hard proof that this approach is unacceptably slow or
heavy on the resources.

It seems likely that it will not be, in this case, so
just doing the file open() is almost certainly the best
thing, not to mention that it saves you all that time
doing measurements and worrying about it all...

-Peter



More information about the Python-list mailing list