Why no isexec, isread, iswrite, etc (was: I must be missing something obvious: os.path.isexecutable?)

Grant Edwards grante at visi.com
Fri Jan 19 14:50:34 EST 2001


In article <slrn96erlf.h11.grey at teleute.rpglink.com>, Steve Lamb wrote:

>    then I foudn the above mentioned conversation with the macros from stat
>coming into play.  So I dug into os.path.py, bounced into posixpath.py, and
>see that isdir, isfile and islink use the stat macros.  So why not complete
>the suite of tests possible from the stat macros and have read/write/exec
>tests in there as well?

One answer: 

You are checking something for readibility because you want to
try to read it.  Just go ahead and try to open and read it.  If
it's not readable you'll get an exception telling you so.

Since the file may be deleted, moved, or its protection bits
changed between the stat() call and the open(), you have to be
prepared to handle error returns from the open() call.  That
said, it's a waste of effort to check to see if it is readable.

[Same answer if you're going to try to write or exec a file.]

-- 
Grant Edwards                   grante             Yow!  You should all JUMP
                                  at               UP AND DOWN for TWO HOURS
                               visi.com            while I decide on a NEW
                                                   CAREER!!



More information about the Python-list mailing list