path module

Andrew Dalke adalke at mindspring.com
Fri Jul 25 19:21:15 EDT 2003


holger krekel
> We currently only have one 'visit' method that accepts a filter for
returning
> 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 &&
nolink".
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"))
  -or-
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.

                    Andrew
                    dalke at dalkescientific.com






More information about the Python-list mailing list