[Python-ideas] fnmatch.filter_false

tritium-list at sdamon.com tritium-list at sdamon.com
Wed May 17 13:19:28 EDT 2017

> -----Original Message-----
> From: Python-ideas [mailto:python-ideas-bounces+tritium-
> list=sdamon.com at python.org] On Behalf Of Oleg Broytman
> Sent: Wednesday, May 17, 2017 12:44 PM
> To: python-ideas at python.org
> Subject: Re: [Python-ideas] fnmatch.filter_false
> On Wed, May 17, 2017 at 12:14:05PM -0400, Alex Walters <tritium-
> list at sdamon.com> wrote:
> > Fnmath.filter works great.  To remind people what it does, it takes an
> > iterable of strings and a pattern and returns a list of the strings that
> > match the pattern.  And that is wonderful
> >
> > However, I often need to filter *out* the items that match the pattern
> > ignore them).  In every project that I need this I end up copying the
> > function out of the fnmatch library and adding 'not' to the test clause.
> > would be wonderful if there was a filter_false version in the standard
> > library.  Or in inversion Boolean option.  Or something, to stop from
> > to copy code every time I need to ignore files.
>    Why not create a package and publish at PyPI? Then all you need is
> pip install fnmatch_filter_false
>    in your virtual env.

That is my normal thought on something like this, but in the case of adding
a Boolean argument to fnmatch.filter, it (might be) as simple as a 3 line
diff that does not break the API, and as far as I can tell, does not have
performance implications.  Copying a module out of the standard library that
is identical except a 3 line diff that does not break compatibility with the
standard library... that just wreaks of something that should be in the
standard library to begin with.

In the case of adding a separate function to fnmatch, it's still not that
big of a diff, and wouldn't have much duplicated code, at least in the way I
would implement it - it would essentially do the previous Boolean option
method, and wrap that.  A filter_false function, now that I think about it,
is less ideal than just adding a keyword only Boolean option to

> Oleg.
> --
>      Oleg Broytman            http://phdru.name/            phd at phdru.name
>            Programmers don't die, they just GOSUB without RETURN.
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/

More information about the Python-ideas mailing list