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

MRAB python at mrabarnett.plus.com
Fri Nov 9 18:13:15 CET 2012

On 2012-11-09 14:42, Christian Heimes wrote:
> Am 09.11.2012 11:29, schrieb Ben Hoyt:
>> * Changing listdir() to yield instead of return a list (or adding yieldir?).
>> This fits both the FindNext/readdir APIs, and would address issues like [3].
>> Anyway, cutting a long story short -- do folks think 1) is a good idea? What
>> about some of the thoughts in 2)? In either case, what would be the best way
>> to go further on this?
> +1 for something like yielddir().
+1, although I would prefer it to be called something like iterdir().

> I while ago I proposed that the os module shall get another function for
> iterating over a directory. The new function is to return a generator
> that yields structs. The structs contain the name and additional
> metadata that like the d_type. On Unix it should use the reentrant
> version of readdir(), too.
> A struct has the benefit that it can grow additional fields or contain
> operating dependent information like inode on Unix.

More information about the Python-ideas mailing list