@@ -34,9 +34,7 @@ unlike :func:`fnmatch.fnmatch` or :func:`pathlib.Path.glob`.
3434For a literal match, wrap the meta-characters in brackets.
3535For example, ``'[?]' `` matches the character ``'?' ``.
3636
37-
38- .. seealso ::
39- The :mod: `pathlib ` module offers high-level path objects.
37+ The :mod: `glob ` module defines the following functions:
4038
4139
4240.. function :: glob(pathname, *, root_dir=None, dir_fd=None, recursive=False, \
@@ -117,35 +115,6 @@ For example, ``'[?]'`` matches the character ``'?'``.
117115 .. versionadded :: 3.4
118116
119117
120- For example, consider a directory containing the following files:
121- :file: `1.gif `, :file: `2.txt `, :file: `card.gif ` and a subdirectory :file: `sub `
122- which contains only the file :file: `3.txt `. :func: `glob ` will produce
123- the following results. Notice how any leading components of the path are
124- preserved. ::
125-
126- >>> import glob
127- >>> glob.glob('./[0-9].*')
128- ['./1.gif', './2.txt']
129- >>> glob.glob('*.gif')
130- ['1.gif', 'card.gif']
131- >>> glob.glob('?.gif')
132- ['1.gif']
133- >>> glob.glob('**/*.txt', recursive=True)
134- ['2.txt', 'sub/3.txt']
135- >>> glob.glob('./**/', recursive=True)
136- ['./', './sub/']
137-
138- If the directory contains files starting with ``. `` they won't be matched by
139- default. For example, consider a directory containing :file: `card.gif ` and
140- :file: `.card.gif `::
141-
142- >>> import glob
143- >>> glob.glob('*.gif')
144- ['card.gif']
145- >>> glob.glob('.c*')
146- ['.card.gif']
147-
148-
149118.. function :: translate(pathname, *, recursive=False, include_hidden=False, seps=None)
150119
151120 Convert the given path specification to a regular expression for use with
@@ -184,7 +153,39 @@ default. For example, consider a directory containing :file:`card.gif` and
184153 .. versionadded :: 3.13
185154
186155
156+ Examples
157+ --------
158+
159+ Consider a directory containing the following files:
160+ :file: `1.gif `, :file: `2.txt `, :file: `card.gif ` and a subdirectory :file: `sub `
161+ which contains only the file :file: `3.txt `. :func: `glob ` will produce
162+ the following results. Notice how any leading components of the path are
163+ preserved. ::
164+
165+ >>> import glob
166+ >>> glob.glob('./[0-9].*')
167+ ['./1.gif', './2.txt']
168+ >>> glob.glob('*.gif')
169+ ['1.gif', 'card.gif']
170+ >>> glob.glob('?.gif')
171+ ['1.gif']
172+ >>> glob.glob('**/*.txt', recursive=True)
173+ ['2.txt', 'sub/3.txt']
174+ >>> glob.glob('./**/', recursive=True)
175+ ['./', './sub/']
176+
177+ If the directory contains files starting with ``. `` they won't be matched by
178+ default. For example, consider a directory containing :file: `card.gif ` and
179+ :file: `.card.gif `::
180+
181+ >>> import glob
182+ >>> glob.glob('*.gif')
183+ ['card.gif']
184+ >>> glob.glob('.c*')
185+ ['.card.gif']
186+
187187.. seealso ::
188+ The :mod: `fnmatch ` module offers shell-style filename (not path) expansion.
188189
189- Module :mod: ` fnmatch `
190- Shell-style filename (not path) expansion
190+ .. seealso ::
191+ The :mod: ` pathlib ` module offers high-level path objects.
0 commit comments