diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2015-04-04 11:01:02 +0300 |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2015-04-04 11:01:02 +0300 |
commit | 46ba6c8563922f043cad6423202ee0119614c807 (patch) | |
tree | 4523d1a3665af25ef77898f7d2da186fbdca8ce7 /Lib/pydoc.py | |
parent | ae2d667ae83548029fed7244619fadd7f625cb24 (diff) | |
download | cpython-git-46ba6c8563922f043cad6423202ee0119614c807.tar.gz |
Issue #22831: Use "with" to avoid possible fd leaks.
Diffstat (limited to 'Lib/pydoc.py')
-rwxr-xr-x | Lib/pydoc.py | 5 |
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) |