[Python-Dev] Updates to PEP 471, the os.scandir() proposal

Nick Coghlan ncoghlan at gmail.com
Sat Jul 12 17:07:03 CEST 2014

On 11 Jul 2014 12:46, "Ben Hoyt" <benhoyt at gmail.com> wrote:
> [replying to python-dev this time]
> >> The "onerror" approach can also deal with readdir failing, which the
> >>  PEP currently glosses over.
> >
> >
> > Do we want this, though?  I can see an error handler for individual
> > but if one of the *dir commands fails that would seem to be fairly
> > catastrophic.
> Very much agreed that this isn't necessary for just readdir/FindNext
> errors. We've never had this level of detail before -- if listdir()
> fails half way through (very unlikely) it just bombs with OSError and
> you get no entries at all.
> If you really really want this (again very unlikely), you can always
> use call next() directly and catch OSError around that call.

Agreed - I think the PEP should point this out explicitly, and show that
the approach it takes offers a lot of flexibility in error handling from
"just let it fail", to a single try/catch around the whole loop, to
try/catch just around the operations that might call lstat(), to try/catch
around the individual iteration steps.

os.walk remains the higher level API that most code should be using, and
that has to retain the current listdir based behaviour (any error = ignore
all entries in that directory) for backwards compatibility reasons.


> -Ben
> _______________________________________________
> Python-Dev mailing list
> Python-Dev at python.org
> https://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20140712/21d42e20/attachment.html>

More information about the Python-Dev mailing list