diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2015-04-04 08:01:02 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2015-04-04 08:01:02 (GMT) |
commit | 46ba6c8563922f043cad6423202ee0119614c807 (patch) | |
tree | 4523d1a3665af25ef77898f7d2da186fbdca8ce7 /Lib/token.py | |
parent | ae2d667ae83548029fed7244619fadd7f625cb24 (diff) | |
download | cpython-46ba6c8563922f043cad6423202ee0119614c807.zip cpython-46ba6c8563922f043cad6423202ee0119614c807.tar.gz cpython-46ba6c8563922f043cad6423202ee0119614c807.tar.bz2 |
Issue #22831: Use "with" to avoid possible fd leaks.
Diffstat (limited to 'Lib/token.py')
-rw-r--r-- | Lib/token.py | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/Lib/token.py b/Lib/token.py index bdfcec8..a95d9b7 100644 --- a/Lib/token.py +++ b/Lib/token.py @@ -97,8 +97,8 @@ def _main(): except OSError as err: sys.stdout.write("I/O error: %s\n" % str(err)) sys.exit(1) - lines = fp.read().split("\n") - fp.close() + with fp: + lines = fp.read().split("\n") prog = re.compile( "#define[ \t][ \t]*([A-Z0-9][A-Z0-9_]*)[ \t][ \t]*([0-9][0-9]*)", re.IGNORECASE) @@ -116,8 +116,8 @@ def _main(): except OSError as err: sys.stderr.write("I/O error: %s\n" % str(err)) sys.exit(2) - format = fp.read().split("\n") - fp.close() + with fp: + format = fp.read().split("\n") try: start = format.index("#--start constants--") + 1 end = format.index("#--end constants--") @@ -133,8 +133,8 @@ def _main(): except OSError as err: sys.stderr.write("I/O error: %s\n" % str(err)) sys.exit(4) - fp.write("\n".join(format)) - fp.close() + with fp: + fp.write("\n".join(format)) if __name__ == "__main__": |