path module

Ian Bicking ianb at colorstudy.com
Fri Jul 25 15:17:48 EDT 2003


On Fri, 2003-07-25 at 13:33, holger krekel wrote:
> Ian Bicking wrote:
> > Jason had walkers both for all files, just non-directory files, and
> > directory files.  This seems useful to me, and by making it explicit I
> > might just start distinguishing text from binary (which I don't now
> > because I am forgetful).  And a globbing walker, though I don't know how
> > much of an advantage that would be over list comprehension.  Actually,
> > all his walkers have a globbing option.
> 
> We currently only have one 'visit' method that accepts a filter for returning
> results and a filter for recursing into the tree. You can use and
> combine multiple filters like so:
> 
>     root = Path('...)
>     for path in root.visit(AND(isdir, nolink)):
>         # iterates over all non-link dirs in the tree (breadth-first)
> 
> or
> 
>     for path in root.visit(AND(isfile, endswith('.txt')), nodotfile):
>         # iterates over all '*.txt' files but not recursing into ".*"
> 
> and so on.  This proved to be flexible and convenient and mostly avoids
> the need for multiple walk-methods.  

Yeah... but we know that's not going to get into the standard library. 
It requires a big namespace, logic functions (AND, OR, etc.), and it
confuses functions with these filter objects, which are named the same
(and even if the filter objects can be used as functions, it's still
confusing).  It's a style that doesn't exist in the standard library,
and it seems unlikely that it would get in here.

The multiple walk methods would only be a shortcut anyway.  Again, they
might be difficult in a situation like a URL where directory and file
are intermingled (and maybe ReiserFS 4...?) -- which maybe is okay, a
urlpath object simply wouldn't implement that walker.

  Ian







More information about the Python-list mailing list