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. (For tilde and shell variable expansion, useos.path.expanduser() andos.path.expandvars().)
See also
Latest version of theglob module Python source code
Return aniterator which yields the same values asglob()without actually storing them all simultaneously.
New in version 2.5.
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']
See also
10.6.tempfile — Generate temporary files and directories
10.8.fnmatch — Unix filename pattern matching
Enter search terms or a module, class or function name.