summaryrefslogtreecommitdiff
path: root/Lib/argparse.py
diff options
context:
space:
mode:
authorGiampaolo Rodola' <g.rodola@gmail.com>2013-02-12 02:04:27 +0100
committerGiampaolo Rodola' <g.rodola@gmail.com>2013-02-12 02:04:27 +0100
commit2f50aaf2ff427fb713e82699a6dcbeeb038b10c2 (patch)
tree0e2c24897b8918f19d8504915ccebd466c0bbd92 /Lib/argparse.py
parentfd6e6cfa29b2289e711dc7f57f36897c78899ee7 (diff)
downloadcpython-git-2f50aaf2ff427fb713e82699a6dcbeeb038b10c2.tar.gz
modernize some modules' code by using with statement around open()
Diffstat (limited to 'Lib/argparse.py')
-rw-r--r--Lib/argparse.py5
1 files changed, 1 insertions, 4 deletions
diff --git a/Lib/argparse.py b/Lib/argparse.py
index 1c07110816..71dfdda004 100644
--- a/Lib/argparse.py
+++ b/Lib/argparse.py
@@ -2010,16 +2010,13 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer):
# replace arguments referencing files with the file content
else:
try:
- args_file = open(arg_string[1:])
- try:
+ with open(arg_string[1:]) as args_file:
arg_strings = []
for arg_line in args_file.read().splitlines():
for arg in self.convert_arg_line_to_args(arg_line):
arg_strings.append(arg)
arg_strings = self._read_args_from_files(arg_strings)
new_arg_strings.extend(arg_strings)
- finally:
- args_file.close()
except OSError:
err = _sys.exc_info()[1]
self.error(str(err))