xlistdir -- an iterator version of os.listdir

Mongryong Mongryong at sympatico.ca
Sun Jan 26 12:26:14 EST 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
significant.

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")
> 1
> >>> fnmatch("pepe.tx", "*.txt")
> 0
> 
> Apply that inside the loop and you have your memory minimal custom glob.
> 
> -- 
> http://mail.python.org/mailman/listinfo/python-list







More information about the Python-list mailing list