[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 02:37:08 CET 2012


Very good questions.

> 1) Is there some way to distinguish that your st_mode field is only
> partially there (i.e. - you get the Linux/BSD d_type value, but not
> the rest of st_mode)?

Not currently. I haven't thought about this too hard -- there way be a
bit that's always set/not set within st_mode itself. Otherwise I'd
have to add a full_st_mode or similar property

> 2) How about making these attributes properties, so that touching one
> that isn't there causes them all to be populated.

Interesting thought. Might be a bit too magical for my taste.

One concern I have with either of the above (adding a property to
stat_result) is that then I'd have to use my own class or namedtuple
rather than os.stat_result. Presumably that's not a big deal, though,
as you'd never do isinstance testing on it. In the case of 2), it
might have to be a class, meaning somewhat heavier memory-wise for
lots and lots of files.

-Ben



More information about the Python-ideas mailing list