xlistdir -- an iterator version of os.listdir
Mongryong at sympatico.ca
Sun Jan 26 18:26:14 CET 2003
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). Now, if you only wanted to process
all the ".txt" files, you don't want your cache filled with files you
don't need. This is really just an extra feature for optimization
tweaking. In all likelihood, the optimization gains is probably not
Thanks for xlistdir!
On Sun, 2003-01-26 at 11:59, Grzegorz Adam Hankiewicz wrote:
> > On Sun, 2003-01-26 at 00:17, Terrel Shumway wrote:
> > > xlistdir.xlistdir is an iterator version of os.listdir.
> On Sun, Jan 26, 2003 at 10:35:06AM -0500, Mongryong wrote:
> > It would also be nice to be able to list files allow with a certain
> > pattern or suffix.
> Well, you could filter yourself with fnmatch, here's a usage example:
> [gregorio at pedos.es:0] [~]$ python
> imporPython 2.2.1 (#1, Apr 21 2002, 08:38:44)
> [GCC 2.95.4 20011002 (Debian prerelease)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> from fnmatch import *
> >>> fnmatch("pepe.txt", "*.txt")
> >>> fnmatch("pepe.tx", "*.txt")
> Apply that inside the loop and you have your memory minimal custom glob.
More information about the Python-list