[Python-ideas] Make fnmatch.filter accept a tuple of patterns

Stephen J. Turnbull turnbull.stephen.fw at u.tsukuba.ac.jp
Fri Nov 2 13:49:00 EDT 2018


Andre Delfino writes:

 > Frequently, while globbing, one needs to work with multiple extensions. I’d
 > like to propose for fnmatch.filter to handle a tuple of patterns (while
 > preserving the single str argument functionality, alas str.endswith),

This is one of those famous 3-line functions, though:

    import fnmatch
    def multifilter(names, *patterns):
        result = []
        for p in patterns:
            result.extend(fnmatch.filter(names, p)
        return result

It's a 3-line function in 5 lines, OK, but still.

 > as a first step for glob.i?glob to accept multiple patterns as well.

If you're going to improve the glob module, why not use bash or zsh
extended globbing ('**', '{a,b}') as the model?  This is more
powerful, and already familiar to many users.



More information about the Python-ideas mailing list