glob module adds a necessary Unix shell
capability to Windows programmers. The
module includes the following function
list of filenames that match
the given wild-card pattern. The
module is used for the wild-card pattern matching.
A common use for
glob is something like the
following under Windows.
import glob, sys
for arg in sys.argv[1:]:
for f in glob.glob(arg):
process( f )
This makes Windows programs process command line arguments
somewhat like Unix programs. Each argument is passed to
glob.glob to expand any patterns into a
list of matching files. If the argument is not a
wild-card pattern, glob simply returns a
containing this one file name.
fnmatch module has the algorithm for
actually matching a wild-card pattern against specific file names. This
module implements the Unix shell wild-card rules. These are not the same
as the more sophisticated regular expression rules. The module contains
the following function:
) → boolean
Return True if the file matches the pattern.
The patterns use
* to match any number of
? to match any single character.
[letters] matches any of these letters, and
[!letters] matches any letter that is not in the
given set of letters.