@@ -34,9 +34,7 @@ unlike :func:`fnmatch.fnmatch` or :func:`pathlib.Path.glob`.
34
34
For a literal match, wrap the meta-characters in brackets.
35
35
For example, ``'[?]' `` matches the character ``'?' ``.
36
36
37
-
38
- .. seealso ::
39
- The :mod: `pathlib ` module offers high-level path objects.
37
+ The :mod: `glob ` module defines the following functions:
40
38
41
39
42
40
.. function :: glob(pathname, *, root_dir=None, dir_fd=None, recursive=False, \
@@ -117,35 +115,6 @@ For example, ``'[?]'`` matches the character ``'?'``.
117
115
.. versionadded :: 3.4
118
116
119
117
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
-
149
118
.. function :: translate(pathname, *, recursive=False, include_hidden=False, seps=None)
150
119
151
120
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
184
153
.. versionadded :: 3.13
185
154
186
155
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
+
187
187
.. seealso ::
188
+ The :mod: `fnmatch ` module offers shell-style filename (not path) expansion.
188
189
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