]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #16695: Document how glob handles filenames starting with a dot
authorPetri Lehtinen <petri@digip.org>
Sat, 23 Feb 2013 18:53:03 +0000 (19:53 +0100)
committerPetri Lehtinen <petri@digip.org>
Sat, 23 Feb 2013 18:53:27 +0000 (19:53 +0100)
Doc/library/glob.rst
Lib/glob.py
Misc/NEWS

index 25843619c0d8297b5c942ca442bfb144efbe4ef7..eff138b3308e14b66a87666debd4095ed4161e21 100644 (file)
@@ -16,8 +16,10 @@ 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`.)
+subshell.  Note that unlike :func:`fnmatch.fnmatch`, :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 ``'?'``.
@@ -51,6 +53,15 @@ preserved. ::
    >>> glob.glob('?.gif')
    ['1.gif']
 
+If the directory contains files starting with ``.`` they won't be matched by
+default. For example, consider a directory containing :file:`card.gif` and
+:file:`.card.gif`::
+
+   >>> import glob
+   >>> glob.glob('*.gif')
+   ['card.gif']
+   >>> glob.glob('.c*')
+   ['.card.gif']
 
 .. seealso::
 
index f16e8e16e420295f201fa59d37f88e00b038c022..1f602656d0881bb3758638ef7b73151acda4038a 100644 (file)
@@ -9,7 +9,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, filenames starting with a
+    dot are special cases that are not matched by '*' and '?'
+    patterns.
 
     """
     return list(iglob(pathname))
@@ -17,7 +20,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, filenames starting with a
+    dot are special cases that are not matched by '*' and '?'
+    patterns.
 
     """
     if not has_magic(pathname):
index 1550d0e6abeb9c1ac7d3380a6fd18ee27ccf226d..73ad78a888e760ff697ee8ba60eb5e764d40b788 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -1078,6 +1078,9 @@ Tools/Demos
 Documentation
 -------------
 
+- Issue #16695: Document how glob handles filenames starting with a
+  dot. Initial patch by Jyrki Pulliainen.
+
 - Issue #8890: Stop advertising an insecure practice by replacing uses
   of the /tmp directory with better alternatives in the documentation.
   Patch by Geoff Wilson.