[Python-ideas] Optional argument to fnmatch functions treat * and ** differently

Aaron lists at whitehouse.kiwi.nz
Tue Feb 28 16:27:08 EST 2017


I would like fnmatch.fnmatch to have a mode where:
     **     matches any files and zero or more directories and 
subdirectories (i.e. the current behaviour of *)
     *       matches in one path level/only to the next path separator

This is essentially achievable in glob.glob from version 3.5 (with 
recursive=True), but glob is not suitable for my use case, as I need to 
work with strings and not files. I would like to gauge whether adding 
such behaviour behind an optional argument similar to glob's "recursive" 
(e.g. "glob_asterisks=False") is likely to be accepted into the standard 
library, before I start working on a patch.

I have seen people raise the question of how to achieve this in a number 
of places. Somebody has also forked the Python 2 standard library 
fnmatch module to implement this as a standalone library:
(which shows that the actual changes are likely to be pretty small).

This request is also discussed in the following bug:

Not directly on point, but some may find the discussion interesting:


I would appreciate any thoughts.

Kind regards,


More information about the Python-ideas mailing list