[Python-ideas] PEP471 - (os.scandir())
Erik
python at lucidity.plus.com
Thu Nov 26 18:22:25 EST 2015
PEP471 introduces a faster way of doing low-level directory traversal
which is then used to implement and speed up the higher-level API
os.walk() - which for me at least is the "go to API" for most directory
scanning code I write.
However, when using os.walk() the first thing that one tends to do with
the results is to analyse them in some way (look at file sizes,
datestamps and other things that stat() returns) which is exactly the
information that os.scandir() is caching and speeding up but which is
then thrown away in order to emulate os.walk()'s original name-based API
(well, name and type as the directory/file distinction is also there).
So, I'd like to suggest an os.walk()-like API that returns the
os.scandir() DirEntry structures rather than names (*). I have my own
local version that's just a copy of os.walk() that appends "entry"
rather than "entry.name" to the returned lists, but that's a nasty way
of achieving this.
How to do it -
os.walk() "direntries=True" keyword?
os.walkentries() function?
Something else better than those?
Regards, E.
(*) I have studied the PEP, followed a lot of the references and looked
at the 3.5.0 implementation. I can't see that I've missed such a thing
already existing, but it's possible. If so, perhaps this is instead a
request to make that thing more obvious somehow!
More information about the Python-ideas
mailing list