From b55d8e807d5cdb1135f1a3873ce16370e589394f Mon Sep 17 00:00:00 2001 From: totosuki Date: Mon, 9 Dec 2024 23:56:23 +0900 Subject: [PATCH 1/9] Update os.walk example --- Doc/library/os.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Doc/library/os.rst b/Doc/library/os.rst index dfe5ef0726ff7d..8e92d0ede8e742 100644 --- a/Doc/library/os.rst +++ b/Doc/library/os.rst @@ -3665,7 +3665,7 @@ features: This example displays the number of bytes taken by non-directory files in each directory under the starting directory, except that it doesn't look under any - CVS subdirectory:: + \_\_pycache\_\_ subdirectory:: import os from os.path import join, getsize @@ -3673,8 +3673,8 @@ features: print(root, "consumes", end=" ") print(sum(getsize(join(root, name)) for name in files), end=" ") print("bytes in", len(files), "non-directory files") - if 'CVS' in dirs: - dirs.remove('CVS') # don't visit CVS directories + if '__pycache__' in dirs: + dirs.remove('__pycache__') # don't visit __pycache__ directories In the next example (simple implementation of :func:`shutil.rmtree`), walking the tree bottom-up is essential, :func:`rmdir` doesn't allow From 3da9a2ab8f835eaad346d7aab903e28c7a813888 Mon Sep 17 00:00:00 2001 From: Totosuki <116938397+totosuki@users.noreply.github.com> Date: Tue, 10 Dec 2024 00:56:21 +0900 Subject: [PATCH 2/9] Update Doc/library/os.rst MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com> --- Doc/library/os.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/os.rst b/Doc/library/os.rst index 8e92d0ede8e742..f10083d69a2daa 100644 --- a/Doc/library/os.rst +++ b/Doc/library/os.rst @@ -3665,7 +3665,7 @@ features: This example displays the number of bytes taken by non-directory files in each directory under the starting directory, except that it doesn't look under any - \_\_pycache\_\_ subdirectory:: + ``__pycache__`` subdirectory:: import os from os.path import join, getsize From 108b40c66f758d05f0fb71f9598c7ca83c6bfb1d Mon Sep 17 00:00:00 2001 From: totosuki Date: Tue, 10 Dec 2024 01:09:43 +0900 Subject: [PATCH 3/9] Replace path with os.getcwd() --- Doc/library/os.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/os.rst b/Doc/library/os.rst index f10083d69a2daa..fc925598c3b97f 100644 --- a/Doc/library/os.rst +++ b/Doc/library/os.rst @@ -3669,7 +3669,7 @@ features: import os from os.path import join, getsize - for root, dirs, files in os.walk('python/Lib/email'): + for root, dirs, files in os.walk(os.getcwd()): print(root, "consumes", end=" ") print(sum(getsize(join(root, name)) for name in files), end=" ") print("bytes in", len(files), "non-directory files") From 0409ac8c38d770a52c3cbae2d408c64e655307d9 Mon Sep 17 00:00:00 2001 From: totosuki Date: Tue, 10 Dec 2024 01:30:34 +0900 Subject: [PATCH 4/9] Replace path with python/Lib --- Doc/library/os.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/os.rst b/Doc/library/os.rst index fc925598c3b97f..5fedce45f37884 100644 --- a/Doc/library/os.rst +++ b/Doc/library/os.rst @@ -3669,7 +3669,7 @@ features: import os from os.path import join, getsize - for root, dirs, files in os.walk(os.getcwd()): + for root, dirs, files in os.walk("python/Lib"): print(root, "consumes", end=" ") print(sum(getsize(join(root, name)) for name in files), end=" ") print("bytes in", len(files), "non-directory files") From d14831c44eefeab3a26dad526e56cddd0686d3a5 Mon Sep 17 00:00:00 2001 From: totosuki Date: Tue, 10 Dec 2024 01:41:48 +0900 Subject: [PATCH 5/9] Fix quotes --- Doc/library/os.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/os.rst b/Doc/library/os.rst index 5fedce45f37884..55a98243d43c95 100644 --- a/Doc/library/os.rst +++ b/Doc/library/os.rst @@ -3669,7 +3669,7 @@ features: import os from os.path import join, getsize - for root, dirs, files in os.walk("python/Lib"): + for root, dirs, files in os.walk('python/Lib'): print(root, "consumes", end=" ") print(sum(getsize(join(root, name)) for name in files), end=" ") print("bytes in", len(files), "non-directory files") From f819a76b9c2a1c310c57a48db30dba1ffccba9ad Mon Sep 17 00:00:00 2001 From: totosuki Date: Tue, 10 Dec 2024 09:18:43 +0900 Subject: [PATCH 6/9] Update os.walk docstrings --- Lib/os.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Lib/os.py b/Lib/os.py index 9c2258e6ccf5ba..cf212f1bd38df6 100644 --- a/Lib/os.py +++ b/Lib/os.py @@ -345,12 +345,12 @@ def walk(top, topdown=True, onerror=None, followlinks=False): import os from os.path import join, getsize - for root, dirs, files in os.walk('python/Lib/email'): + for root, dirs, files in os.walk('python/Lib'): print(root, "consumes ") print(sum(getsize(join(root, name)) for name in files), end=" ") print("bytes in", len(files), "non-directory files") - if 'CVS' in dirs: - dirs.remove('CVS') # don't visit CVS directories + if '__pycache__' in dirs: + dirs.remove('__pycache__') # don't visit __pycache__ directories """ sys.audit("os.walk", top, topdown, onerror, followlinks) From 51c58e3c5b3c0bc36779067fd242df5db51ba072 Mon Sep 17 00:00:00 2001 From: totosuki Date: Tue, 10 Dec 2024 09:20:34 +0900 Subject: [PATCH 7/9] Update os.fwalk docstrings --- Lib/os.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Lib/os.py b/Lib/os.py index cf212f1bd38df6..c3f9f40479d87f 100644 --- a/Lib/os.py +++ b/Lib/os.py @@ -460,13 +460,13 @@ def fwalk(top=".", topdown=True, onerror=None, *, follow_symlinks=False, dir_fd= Example: import os - for root, dirs, files, rootfd in os.fwalk('python/Lib/email'): + for root, dirs, files, rootfd in os.fwalk('python/Lib'): print(root, "consumes", end="") print(sum(os.stat(name, dir_fd=rootfd).st_size for name in files), end="") print("bytes in", len(files), "non-directory files") - if 'CVS' in dirs: - dirs.remove('CVS') # don't visit CVS directories + if '__pycache__' in dirs: + dirs.remove('__pycache__') # don't visit __pycache__ directories """ sys.audit("os.fwalk", top, topdown, onerror, follow_symlinks, dir_fd) top = fspath(top) From 00753f5ad5c60117df9382ddd00bd8e5db649731 Mon Sep 17 00:00:00 2001 From: totosuki Date: Tue, 10 Dec 2024 09:27:37 +0900 Subject: [PATCH 8/9] Update os.fwalk example --- Doc/library/os.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Doc/library/os.rst b/Doc/library/os.rst index 55a98243d43c95..cbbb5789a89920 100644 --- a/Doc/library/os.rst +++ b/Doc/library/os.rst @@ -3727,16 +3727,16 @@ features: This example displays the number of bytes taken by non-directory files in each directory under the starting directory, except that it doesn't look under any - CVS subdirectory:: + ``__pycache__`` subdirectory:: import os - for root, dirs, files, rootfd in os.fwalk('python/Lib/email'): + for root, dirs, files, rootfd in os.fwalk('python/Lib'): print(root, "consumes", end="") print(sum([os.stat(name, dir_fd=rootfd).st_size for name in files]), end="") print("bytes in", len(files), "non-directory files") - if 'CVS' in dirs: - dirs.remove('CVS') # don't visit CVS directories + if '__pycache__' in dirs: + dirs.remove('__pycache__') # don't visit __pycache__ directories In the next example, walking the tree bottom-up is essential: :func:`rmdir` doesn't allow deleting a directory before the directory is From 87e0dcddb8fd747b71b7a82131a45fd302e4524f Mon Sep 17 00:00:00 2001 From: totosuki Date: Tue, 10 Dec 2024 23:26:56 +0900 Subject: [PATCH 9/9] Use python/Lib/xml in example --- Doc/library/os.rst | 4 ++-- Lib/os.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Doc/library/os.rst b/Doc/library/os.rst index cbbb5789a89920..98cd0b9359cefa 100644 --- a/Doc/library/os.rst +++ b/Doc/library/os.rst @@ -3669,7 +3669,7 @@ features: import os from os.path import join, getsize - for root, dirs, files in os.walk('python/Lib'): + for root, dirs, files in os.walk('python/Lib/xml'): print(root, "consumes", end=" ") print(sum(getsize(join(root, name)) for name in files), end=" ") print("bytes in", len(files), "non-directory files") @@ -3730,7 +3730,7 @@ features: ``__pycache__`` subdirectory:: import os - for root, dirs, files, rootfd in os.fwalk('python/Lib'): + for root, dirs, files, rootfd in os.fwalk('python/Lib/xml'): print(root, "consumes", end="") print(sum([os.stat(name, dir_fd=rootfd).st_size for name in files]), end="") diff --git a/Lib/os.py b/Lib/os.py index c3f9f40479d87f..266e40b56f6c81 100644 --- a/Lib/os.py +++ b/Lib/os.py @@ -345,7 +345,7 @@ def walk(top, topdown=True, onerror=None, followlinks=False): import os from os.path import join, getsize - for root, dirs, files in os.walk('python/Lib'): + for root, dirs, files in os.walk('python/Lib/xml'): print(root, "consumes ") print(sum(getsize(join(root, name)) for name in files), end=" ") print("bytes in", len(files), "non-directory files") @@ -460,7 +460,7 @@ def fwalk(top=".", topdown=True, onerror=None, *, follow_symlinks=False, dir_fd= Example: import os - for root, dirs, files, rootfd in os.fwalk('python/Lib'): + for root, dirs, files, rootfd in os.fwalk('python/Lib/xml'): print(root, "consumes", end="") print(sum(os.stat(name, dir_fd=rootfd).st_size for name in files), end="")