xlistdir -- an iterator version of os.listdir
Chris Gonnerman
chris.gonnerman at newcenturycomputers.net
Sun Jan 26 17:30:28 EST 2003
More information about the Python-list mailing list
Sun Jan 26 17:30:28 EST 2003
- Previous message (by thread): xlistdir -- an iterator version of os.listdir
- Next message (by thread): determining method type (instance, static, class)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
----- Original Message ----- From: "Terrel Shumway" <tshumway at jdiworks.net> > xlistdir.xlistdir is an iterator version of os.listdir. > > It is particularly useful if you have a directory with, for example, > 40,000 files, and you only want to look at the first 10. > > from xlistdir import xlistdir > x = xlistdir("directory-with-LOTS-of-files") > > for i in range(10): > print x[i] # or "x.next()" > > > You might also use it to filter the list before allocating it: > > files_only = [ file for file in xlistdir(bigdir) \ > if os.path.isfile(os.path.join(bigdir,file)) ] > > > Most of this code was cut and pasted from xreadlinesmodule.c and posixmodule.c > in Python-2.2.2.tgz > > This initial hack may not even compile on platforms without > opendir/readdir/closedir (e.g. mswin32, mswin16, OS/2) because I do > not have access to those platforms. I tried it using MinGW32 on Win98... after putting in an apparently-missing #include <windows.h>, here is what I got: C:\WINDOWS\Desktop\xlistdir-0.1>python setup.py build --compiler=mingw32 running build running build_py not copying test_xlistdir.py (output up-to-date) running build_ext building 'xlistdir' extension C:\MINGW32\BIN\gcc.exe -mno-cygwin -mdll -O -Wall -IC:\PYTHON\include -c xlistdi rmodule.c -o build\temp.win32-2.2\Release\xlistdirmodule.o xlistdirmodule.c: In function `xlistdir_opendir': xlistdirmodule.c:83: warning: implicit declaration of function `win32_error' xlistdirmodule.c:83: warning: return makes pointer from integer without a cast xlistdirmodule.c:57: warning: unused variable `bufptr' xlistdirmodule.c: In function `xlistdir_closedir': xlistdirmodule.c:104: `op' undeclared (first use in this function) xlistdirmodule.c:104: (Each undeclared identifier is reported only once xlistdirmodule.c:104: for each function it appears in.) xlistdirmodule.c:110: warning: return makes pointer from integer without a cast xlistdirmodule.c: In function `xlistdir_readdir': xlistdirmodule.c:119: `op' undeclared (first use in this function) xlistdirmodule.c:123: structure has no member named `cFilename' xlistdirmodule.c:128: warning: suggest parentheses around && within || error: command 'gcc' failed with exit status 1 > It does include a unit test, and it does pass for me on Linux. 8-) > > If you can build extension modules on MS_WIN32, MS_WIN16, or OS/2 (or others), > please try this out. If you can make it compile and pass the unit tests, > you will get a really cool function to use in your programs and share with > the rest of the python community 8-). Chris Gonnerman -- chris.gonnerman at newcenturycomputers.net http://newcenturycomputers.net
- Previous message (by thread): xlistdir -- an iterator version of os.listdir
- Next message (by thread): determining method type (instance, static, class)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list