diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2019-03-30 08:33:02 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-30 08:33:02 +0200 |
commit | 172bb39452ae8b3ccdf5d1f23ead46f44200cd49 (patch) | |
tree | 5e1effbca3664b839a81eb7a7d62fa4974cfbfb1 /Tools/scripts/fixps.py | |
parent | afbb7a371fb44edc731344eab5b474ad8f7b57d7 (diff) | |
download | cpython-git-172bb39452ae8b3ccdf5d1f23ead46f44200cd49.tar.gz |
bpo-22831: Use "with" to avoid possible fd leaks in tools (part 2). (GH-10927)
Diffstat (limited to 'Tools/scripts/fixps.py')
-rwxr-xr-x | Tools/scripts/fixps.py | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/Tools/scripts/fixps.py b/Tools/scripts/fixps.py index b002261206..725300e56a 100755 --- a/Tools/scripts/fixps.py +++ b/Tools/scripts/fixps.py @@ -14,20 +14,18 @@ def main(): except IOError as msg: print(filename, ': can\'t open :', msg) continue - line = f.readline() - if not re.match('^#! */usr/local/bin/python', line): - print(filename, ': not a /usr/local/bin/python script') - f.close() - continue - rest = f.read() - f.close() + with f: + line = f.readline() + if not re.match('^#! */usr/local/bin/python', line): + print(filename, ': not a /usr/local/bin/python script') + continue + rest = f.read() line = re.sub('/usr/local/bin/python', '/usr/bin/env python', line) print(filename, ':', repr(line)) - f = open(filename, "w") - f.write(line) - f.write(rest) - f.close() + with open(filename, "w") as f: + f.write(line) + f.write(rest) if __name__ == '__main__': main() |