path module

Andrew Dalke adalke at
Sat Jul 26 01:21:15 CEST 2003

holger krekel
> We currently only have one 'visit' method that accepts a filter for
> results and a filter for recursing into the tree.

>     for path in root.visit(AND(isdir, nolink)):

>     for path in root.visit(AND(isfile, endswith('.txt')), nodotfile):

I've used the AND trick before, as well as tricks to support "isdir &&
Still, as these things get more complicated, its easier to just do

for path in root.visit(lambda name: isfile(name) and name.endswith(".txt"))
def myfilter(name):
    return isfile(name) and name.endswith(".txt")
for path in root.visit(myfilter):

rather than use an prefix-style function interface.

This doesn't introduce any new programming styles, which makes it
easier to understand.

The exception is if the result builds up some sort of parse tree which
can be further analyzed for performance, which is not the case here.

                    dalke at

More information about the Python-list mailing list