[Python-Dev] os.walk() silently ignores errors

Alex Martelli aleax@aleax.it
Tue, 13 May 2003 17:29:54 +0200


On Tuesday 13 May 2003 05:06 pm, Harri Pasanen wrote:
   ...
> > 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.

Seconded!  The default of ignoring errors is just fine, but it WOULD
be nice to optionally get a callback on errors so as to be able to
raise warnings or exceptions.  "Errors should never pass silently
unless explicitly silenced" would argue for stronger diagnostic
behavior, but compatibility surely constrain the default behavior --
BUT, an easy way to get non-silent behavior would be something
I'd end up using, roughly, in 50% of my tree-walking scripts.


Alex