<p dir="ltr"><br>
On 11 Jul 2014 12:46, "Ben Hoyt" <<a href="mailto:benhoyt@gmail.com">benhoyt@gmail.com</a>> wrote:<br>
><br>
> [replying to python-dev this time]<br>
><br>
> >> The "onerror" approach can also deal with readdir failing, which the<br>
> >> PEP currently glosses over.<br>
> ><br>
> ><br>
> > Do we want this, though? I can see an error handler for individual entries,<br>
> > but if one of the *dir commands fails that would seem to be fairly<br>
> > catastrophic.<br>
><br>
> Very much agreed that this isn't necessary for just readdir/FindNext<br>
> errors. We've never had this level of detail before -- if listdir()<br>
> fails half way through (very unlikely) it just bombs with OSError and<br>
> you get no entries at all.<br>
><br>
> If you really really want this (again very unlikely), you can always<br>
> use call next() directly and catch OSError around that call.</p>
<p dir="ltr">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.</p>
<p dir="ltr">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.</p>
<p dir="ltr">Cheers,<br>
Nick.</p>
<p dir="ltr">><br>
> -Ben<br>
> _______________________________________________<br>
> Python-Dev mailing list<br>
> <a href="mailto:Python-Dev@python.org">Python-Dev@python.org</a><br>
> <a href="https://mail.python.org/mailman/listinfo/python-dev">https://mail.python.org/mailman/listinfo/python-dev</a><br>
> Unsubscribe: <a href="https://mail.python.org/mailman/options/python-dev/ncoghlan%40gmail.com">https://mail.python.org/mailman/options/python-dev/ncoghlan%40gmail.com</a><br>
</p>