[Python-ideas] Allow iterable argument to os.walk()

John O'Connor jxo6948 at rit.edu
Sun Oct 30 21:51:08 CET 2011


> No, because it means you end up having to special case strings so
> they're treated atomically. We already do that in a few
> string-specific APIs (e.g. startswith()/endswith()), but it's still
> not a particularly nice pattern.

It would be a special case, but I don't understand why that is a bad
thing or why it is appropriate to do in some places but not others.
Perhaps I am missing something. In this case, I think conceptually it
makes sense to perform the "walk" on an iterable and also that one
would expect strings to be treated atomically. I am well aware that
not every 2-3 line recipe needs to be a new function but having more
routines operate on iterables (where it makes sense) seems like a good
idea.

As an aside, I question the aesthetics of yet another for loop for the
following. At least python has a nice for loop construct :)

for dir in dirs:
    for root, dirs, files in os.walk(dir):
        for name in files:
            ....
        for name in dirs:
            ....



More information about the Python-ideas mailing list