This is not exactly what you want, because it just checks to see if a given file is capable of writing. But in case this is useful:
import os filename = "a.txt" if not os.access(filename, os.W_OK): print "Write access not permitted on %s" % filename
(I donβt know of any platform independent way to do what you ask)
source share