Source code:Lib/glob.py
Theglob module finds all the pathnames matching a specified patternaccording to the rules used by the Unix shell. No tilde expansion is done, but*,?, and character ranges expressed with[] will be correctlymatched. This is done by using theos.listdir() andfnmatch.fnmatch() functions in concert, and not by actually invoking asubshell. Note that unlikefnmatch.fnmatch(),glob treatsfilenames beginning with a dot (.) as special cases. (For tilde and shellvariable expansion, useos.path.expanduser() andos.path.expandvars().)
For a literal match, wrap the meta-characters in brackets.For example,'[?]' matches the character'?'.
Return a possibly-empty list of path names that matchpathname, which must bea string containing a path specification.pathname can be either absolute(like/usr/src/Python-1.5/Makefile) or relative (like../../Tools/*/*.gif), and can contain shell-style wildcards. Brokensymlinks are included in the results (as in the shell).
Return aniterator which yields the same values asglob()without actually storing them all simultaneously.
For example, consider a directory containing only the following files:1.gif,2.txt, andcard.gif.glob() will producethe following results. Notice how any leading components of the path arepreserved.
>>>importglob>>>glob.glob('./[0-9].*')['./1.gif', './2.txt']>>>glob.glob('*.gif')['1.gif', 'card.gif']>>>glob.glob('?.gif')['1.gif']
If the directory contains files starting with. they won’t be matched bydefault. For example, consider a directory containingcard.gif and.card.gif:
>>>importglob>>>glob.glob('*.gif')['card.gif']>>>glob.glob('.c*')['.card.gif']
See also
11.5.tempfile — Generate temporary files and directories
11.7.fnmatch — Unix filename pattern matching
Enter search terms or a module, class or function name.