Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e58e0c7

Browse files
committed
clarify when the list of subdirectories is read (closes #13779)
1 parent 9204e09 commit e58e0c7

2 files changed

Lines changed: 12 additions & 8 deletions

File tree

Doc/library/os.rst

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2228,9 +2228,11 @@ features:
22282228

22292229
If optional argument *topdown* is ``True`` or not specified, the triple for a
22302230
directory is generated before the triples for any of its subdirectories
2231-
(directories are generated top-down). If *topdown* is ``False``, the triple for a
2232-
directory is generated after the triples for all of its subdirectories
2233-
(directories are generated bottom-up).
2231+
(directories are generated top-down). If *topdown* is ``False``, the triple
2232+
for a directory is generated after the triples for all of its subdirectories
2233+
(directories are generated bottom-up). No matter the value of *topdown*, the
2234+
list of subdirectories is retrieved before the tuples for the directory and
2235+
its subdirectories are generated.
22342236

22352237
When *topdown* is ``True``, the caller can modify the *dirnames* list in-place
22362238
(perhaps using :keyword:`del` or slice assignment), and :func:`walk` will only

Lib/os.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -312,11 +312,12 @@ def walk(top, topdown=True, onerror=None, followlinks=False):
312312
313313
When topdown is true, the caller can modify the dirnames list in-place
314314
(e.g., via del or slice assignment), and walk will only recurse into the
315-
subdirectories whose names remain in dirnames; this can be used to prune
316-
the search, or to impose a specific order of visiting. Modifying
317-
dirnames when topdown is false is ineffective, since the directories in
318-
dirnames have already been generated by the time dirnames itself is
319-
generated.
315+
subdirectories whose names remain in dirnames; this can be used to prune the
316+
search, or to impose a specific order of visiting. Modifying dirnames when
317+
topdown is false is ineffective, since the directories in dirnames have
318+
already been generated by the time dirnames itself is generated. No matter
319+
the value of topdown, the list of subdirectories is retrieved before the
320+
tuples for the directory and its subdirectories are generated.
320321
321322
By default errors from the os.listdir() call are ignored. If
322323
optional arg 'onerror' is specified, it should be a function; it
@@ -344,6 +345,7 @@ def walk(top, topdown=True, onerror=None, followlinks=False):
344345
print("bytes in", len(files), "non-directory files")
345346
if 'CVS' in dirs:
346347
dirs.remove('CVS') # don't visit CVS directories
348+
347349
"""
348350

349351
islink, join, isdir = path.islink, path.join, path.isdir

0 commit comments

Comments
 (0)