2008-07-15: Selected articles (including this one) now have experimental "comment" links in the left column and at the bottom. You're welcome to use them for commenting and voting on articles. For a bit more on this, see this page. /F

The dircache module

(Obsolete). This module contains a function to get a list of files in a directory. It’s an extension of the os.listdir function, in that it keeps a cache to avoid rereading directories that haven’t been modified.

Example: Using the dircache module
# File: dircache-example-1.py

import dircache

import os, time

# 
# test cached version

t0 = time.clock()

for i in range(100):
    dircache.listdir(os.sep)

print "cached", time.clock() - t0

# 
# test standard version

t0 = time.clock()

for i in range(100):
    os.listdir(os.sep)

print "standard", time.clock() - t0

$ python dircache-example-1.py
cached 0.0664509964968
standard 0.5560845807
 
[comment on/vote for this article]

A Django site. this page was rendered by a django application in 0.02s 2008-07-25 10:59:26.924332. hosted by webfaction.