[Python-Dev] os.walk() silently ignores errors
Harri Pasanen
harri.pasanen@trema.com
Tue, 13 May 2003 17:06:27 +0200
On Tuesday 13 May 2003 15:51, Guido van Rossum wrote:
> > I've just noticed that os.walk() silently skips unreadable
> > directories. I think this is surprising behaviour, which at
> > least should be documented (there is a comment explaining this is
> > source, but nothing in the doc string). Is it too late to add an
> > optional callback argument to handle unreadable directories, so
> > the caller could log them, raise an exception or whatever? I
> > think the default behaviour should still be to silently ignore
> > them, but it would be nice to have a way to override it.
>
> Ignoring is definitely the right thing to do by default, as
> otherwise the existence of a single unreadable directory would
> cause your entire walk to fail. What's your use case for wanting
> to do something else?
Sometimes I'm looking for something in a files in directory tree,
forgetting I don't have access permissions to a particular
subdirectory by default. So the search can silently fail, and I'm
left with the wrong idea that what I was looking is not there.
Ideally, I'd like the possibility have my script remind me to login as
root prior to running it.
I know I could do some defensive programming in the walker function to
go around this, but I this would likely imply more stat calls and
impact performance.
I've been bitten by this a couple of times, so I thought I'd pipe in.
-Harri