[Python-ideas] Speed up os.walk() 5x to 9x by using file attributes from FindFirst/NextFile() and readdir()

Ben Hoyt benhoyt at gmail.com
Thu Nov 15 21:06:31 CET 2012


>> """Yield tuples of (filename, stat_result) for each filename in
>> directory given by "path". Like listdir(), '.' and '..' are skipped.
>> The values are yielded in system-dependent order.
>>
>> Each stat_result is an object like you'd get by calling os.stat() on
>> that file, but not all information is present on all systems, and st_*
>> fields that are not available will be None.
>>
>> In practice, stat_result is a full os.stat() on Windows, but only the
>> "is type" bits of the st_mode field are available on Linux/OS X/BSD.
>> """
>
> There's a code smell here, in that the doc for Unix variants is incomplete
> and wrong. Whether or not you get the d_type values depends on the OS having
> that extension. Further, there's a d_type value (DT_UNKNOWN) that isn't a
> valid value for the S_IFMT bits in st_mode (at least on BSD).

Not sure I understand why the docstring above is incomplete/wrong. I
say "Not all information is present on all systems" and "In practice
... only the 'is type' bits of the st_mode field are available on
Linux/OS X/BSD". All three of those systems provide d_type, so I think
that's correct.

-Ben



More information about the Python-ideas mailing list