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

Christian Heimes christian at python.org
Fri Nov 9 15:42:18 CET 2012

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().

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