Checking File permissions

Lawrence D'Oliveiro ldo at geek-central.gen.new_zealand
Fri Jul 21 01:26:52 EDT 2006


In message <1153401557.444000.92210 at m79g2000cwm.googlegroups.com>, Anoop
wrote:

> Please tell me how to check the existence of a file and the read
> permission to the file using python script

Without knowing what your precise needs are, the best way is to open the
file and try to read from it. If that succeeds, then you've got read
access.

Checking permissions as a separate step from opening the file exposes your
code to a race condition where the permissions may be OK during the initial
check, but then change to deny access before the subsequent open.



More information about the Python-list mailing list