xlistdir -- an iterator version of os.listdir
Grzegorz Adam Hankiewicz
gradha at terra.es
Mon Jan 27 10:44:28 CET 2003
On Sun, Jan 26, 2003 at 12:26:14PM -0500, Mongryong wrote:
> If you're directory has many files, say 50,000, and you require
> to process all of them, it's probably more efficient to cache
> 1000 files at the OS level then it is to have xlistdir.next()
> perform the OS call every time (localization principle).
Well, if the cache is to be done at the OS level, it doesn't matter
if you are using listdir or xlistdir, because it's the OS which
will do it, and python doesn't have any voice about that.
> Now, if you only wanted to process all the ".txt" files, you don't
> want your cache filled with files you don't need.
Well, but the OS is likely going to cache the directory anyway,
even if you just open a single file.
> This is really just an extra feature for optimization tweaking.
> In all likelihood, the optimization gains is probably not
Not for speed, but for memory yes.
More information about the Python-list