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

Ethan Furman ethan at stoneleaf.us
Thu Jul 10 00:12:18 CEST 2014

On 07/09/2014 02:42 PM, Ben Hoyt wrote:
>> Okay, so using that [no platform specific] logic we should head over to the os module and remove:
>> ctermid, getenv, getegid...
>> Okay, I'm tired of typing, but that list is not even half-way through the os
>> page, and those are all methods or attributes that are not available on
>> either Windows or Unix or some flavors of Unix.
> True, is this really the precedent we want to *aim for*. listdir() is
> cross-platform,

and listdir has serious performance issues, which is why you developed scandir.

>> Oh, and all those [snipped] upper-case attributes?  Yup, documented.  And when we
>> don't document it ourselves we often refer readers to their system
>> documentation because Python does not, in fact, return exactly the same
>> results on all platforms -- particularly when calling into the OS.
> But again, why a worse, less cross-platform API when a simple,
> cross-platform one is a method call away?

For the same reason we don't use code that makes threaded behavior better, but kills the single thread application.

If the programmer would rather have consistency on all platforms rather than performance on the one being used, 
`info='lstat'` is the option to use.

I like the 'onerror' API better primarily because it gives a single point to deal with the errors.  This has at least a 
couple advantages:

   - less duplication of code: in the tree_size example, the error
     handling is duplicated twice

   - readablity: with the error handling in a separate routine, one
     does not have to jump around the try/except blocks looking for
     what happens if there are no errors


More information about the Python-Dev mailing list