summaryrefslogtreecommitdiff
path: root/Lib/pydoc.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-04-04 11:01:02 +0300
committerSerhiy Storchaka <storchaka@gmail.com>2015-04-04 11:01:02 +0300
commit46ba6c8563922f043cad6423202ee0119614c807 (patch)
tree4523d1a3665af25ef77898f7d2da186fbdca8ce7 /Lib/pydoc.py
parentae2d667ae83548029fed7244619fadd7f625cb24 (diff)
downloadcpython-git-46ba6c8563922f043cad6423202ee0119614c807.tar.gz
Issue #22831: Use "with" to avoid possible fd leaks.
Diffstat (limited to 'Lib/pydoc.py')
-rwxr-xr-xLib/pydoc.py5
1 files changed, 2 insertions, 3 deletions
diff --git a/Lib/pydoc.py b/Lib/pydoc.py
index 9f3401f766..d77ed002ec 100755
--- a/Lib/pydoc.py
+++ b/Lib/pydoc.py
@@ -1639,9 +1639,8 @@ def writedoc(thing, forceload=0):
try:
object, name = resolve(thing, forceload)
page = html.page(describe(object), html.document(object, name))
- file = open(name + '.html', 'w', encoding='utf-8')
- file.write(page)
- file.close()
+ with open(name + '.html', 'w', encoding='utf-8') as file:
+ file.write(page)
print('wrote', name + '.html')
except (ImportError, ErrorDuringImport) as value:
print(value)