diff --git i/Doc/library/glob.rst w/Doc/library/glob.rst index b881a30..5746464 100644 --- i/Doc/library/glob.rst +++ w/Doc/library/glob.rst @@ -11,13 +11,16 @@ -------------- -The :mod:`glob` module finds all the pathnames matching a specified pattern -according to the rules used by the Unix shell. No tilde expansion is done, but -``*``, ``?``, and character ranges expressed with ``[]`` will be correctly -matched. This is done by using the :func:`os.listdir` and -:func:`fnmatch.fnmatch` functions in concert, and not by actually invoking a -subshell. (For tilde and shell variable expansion, use -:func:`os.path.expanduser` and :func:`os.path.expandvars`.) +The :mod:`glob` module finds all the pathnames matching a specified +pattern according to the rules used by the Unix shell. No tilde +expansion is done, but ``*``, ``?``, and character ranges expressed +with ``[]`` will be correctly matched. This is done by using the +:func:`os.listdir` and :func:`fnmatch.fnmatch` functions in concert, +and not by actually invoking a subshell. Note, that unlike +:func:`fnmatch.fnmatch` the :mod:`glob` treats filenames beginning +with a dot (``.``) as special cases. (For tilde and shell variable +expansion, use :func:`os.path.expanduser` and +:func:`os.path.expandvars`.) For a literal match, wrap the meta-characters in brackets. For example, ``'[?]'`` matches the character ``'?'``. @@ -52,6 +55,14 @@ preserved. :: >>> glob.glob('?.gif') ['1.gif'] +If the directory contains files starting with ``.`` they won't be +matched by default. For example, consider directory containing :file:`card.gif` and :file:`.card.gif` :: + + >>> import glob + >>> glob.glob('c*') + ['card.gif'] + >>> glob.glob('.c*') + ['.card.gif'] .. seealso:: diff --git i/Lib/glob.py w/Lib/glob.py index 0aee605..3a37fd3 100644 --- i/Lib/glob.py +++ w/Lib/glob.py @@ -18,7 +18,10 @@ __all__ = ["glob", "iglob"] def glob(pathname): """Return a list of paths matching a pathname pattern. - The pattern may contain simple shell-style wildcards a la fnmatch. + The pattern may contain simple shell-style wildcards a la + fnmatch. However, unlike fnmatch, the filenames starting with + period are special cases that are not matched by '*' and '?' + patterns. """ return list(iglob(pathname)) @@ -26,7 +29,10 @@ def glob(pathname): def iglob(pathname): """Return an iterator which yields the paths matching a pathname pattern. - The pattern may contain simple shell-style wildcards a la fnmatch. + The pattern may contain simple shell-style wildcards a la + fnmatch. However, unlike fnmatch, the filenames starting with + period are special cases that are not matched by '*' and '?' + patterns. """ if not has_magic(pathname):