fnmatch() vs. glob.glob()

Chris Angelico rosuav at gmail.com
Mon Mar 7 20:56:32 EST 2016


On Tue, Mar 8, 2016 at 12:37 PM, Jinghui Niu <niujinghui at gmail.com> wrote:
> Let me try to describe the behaviours as much as I can here: It is a real-time search, updating the search result as you type; It is very smart, not limiting itself into the verbatim words, but extracting feature strings automatically, e.g., typing "fontz" will match not just "*fontz*", but also "font-size", "fontzipper", etc; It can be switched for certain type of files according specific rules, such as not including ".pyc" files.
>
> My gut feeling is that it is using Regex, but just wonder how I can fit Regex into either fnmatch() or glob() module.

Sounds to me like you're looking at two different things.

1) File name matching, whether with fnmatch or glob, will tell you
which files to look at. You mention excluding .pyc files; you could
specify that only "*.py" be matched, or "*q*.py", or whatever.

2) Regular expression or other searching, within the files.

Either fnmatch or glob will serve you well for the first; I don't
think they're appropriate for the second. But it depends what you're
trying to do.

ChrisA



More information about the Python-list mailing list