summaryrefslogtreecommitdiffstats
path: root/Lib/os.py
diff options
context:
space:
mode:
authorRecursing <buonanno.lorenzo@gmail.com>2018-12-23 03:48:14 (GMT)
committerRaymond Hettinger <rhettinger@users.noreply.github.com>2018-12-23 03:48:14 (GMT)
commit3ce3dea60646d8a5a1c952469a2eb65f937875b3 (patch)
tree145d309073b9d7db0e48a2f0e13822c4a7374492 /Lib/os.py
parentfc8284e22074af8154e9865c8391b955f13a308b (diff)
downloadcpython-3ce3dea60646d8a5a1c952469a2eb65f937875b3.zip
cpython-3ce3dea60646d8a5a1c952469a2eb65f937875b3.tar.gz
cpython-3ce3dea60646d8a5a1c952469a2eb65f937875b3.tar.bz2
Use generator instead of list in code examples (GH-11203)
There is no need to create a list for `sum` Also, becomes consistent with the first example in Doc/library/os.rst
Diffstat (limited to 'Lib/os.py')
-rw-r--r--Lib/os.py4
1 files changed, 2 insertions, 2 deletions
diff --git a/Lib/os.py b/Lib/os.py
index 4b31e4d..7741c75 100644
--- a/Lib/os.py
+++ b/Lib/os.py
@@ -327,7 +327,7 @@ def walk(top, topdown=True, onerror=None, followlinks=False):
from os.path import join, getsize
for root, dirs, files in os.walk('python/Lib/email'):
print(root, "consumes", end="")
- print(sum([getsize(join(root, name)) for name in files]), 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
@@ -446,7 +446,7 @@ if {open, stat} <= supports_dir_fd and {scandir, stat} <= supports_fd:
import os
for root, dirs, files, rootfd in os.fwalk('python/Lib/email'):
print(root, "consumes", end="")
- print(sum([os.stat(name, dir_fd=rootfd).st_size for name in files]),
+ 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: