check whether directory is readable

Ben Finney bignose+hates-spam at
Tue Aug 23 13:38:35 CEST 2005

eels <eels at> wrote:
> how can I check whether a directory is readable or not. Are there
> differences between unix and windows?

The Pythonic way would be to just do what you need to do (in this
case, presumably, read the directory) and catch the specific exception
(in this case, presumably, OSError).

        # Do whatever needs a readable directory

    except OSError, e:
        # Do whatever we need to when the directory is unreadable
        print "Unable to read stuff:", e.strerror

 \         "I got contacts, but I only need them when I read, so I got |
  `\                                      flip-ups."  -- Steven Wright |
_o__)                                                                  |
Ben Finney

More information about the Python-list mailing list