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

Nick Coghlan ncoghlan at gmail.com
Sun Oct 30 01:32:18 CEST 2011


On Sun, Oct 30, 2011 at 8:47 AM, John O'Connor <jxo6948 at rit.edu> wrote:
> Given the push towards iterators in 3.0, is anyone in support of
> allowing an iterable for the "top" argument in os.walk? It seems like
> it would be common to look in more than one directory at once.

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.

If people want to walk multiple directories, 3.3 will make that pretty easy:

    def walk_dirs(dirs):
        for dir in dirs:
            yield from os.walk(dir)

Cheers,
Nick.


-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia



More information about the Python-ideas mailing list