diff options
author | Stefan Behnel <stefan_ml@behnel.de> | 2019-07-27 20:13:58 +0200 |
---|---|---|
committer | Stefan Behnel <stefan_ml@behnel.de> | 2019-07-27 20:13:58 +0200 |
commit | 9126731c12408f507d8c9f19966a002e42462614 (patch) | |
tree | 9121eba0421065d71e471c2e7d4f659a4693517e | |
parent | 929948d44c58b144945654e3bc72845915a3227b (diff) | |
download | python-lxml-9126731c12408f507d8c9f19966a002e42462614.tar.gz |
Modernise some code.
-rw-r--r-- | src/lxml/html/_diffcommand.py | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/src/lxml/html/_diffcommand.py b/src/lxml/html/_diffcommand.py index f99a265b..e0502c0d 100644 --- a/src/lxml/html/_diffcommand.py +++ b/src/lxml/html/_diffcommand.py @@ -51,9 +51,8 @@ def main(args=None): result += '\n' sys.stdout.write(result) else: - f = open(options.output, 'wb') - f.write(result) - f.close() + with open(options.output, 'wb') as f: + f.write(result) def read_file(filename): if filename == '-': @@ -62,9 +61,8 @@ def read_file(filename): raise OSError( "Input file %s does not exist" % filename) else: - f = open(filename, 'rb') - c = f.read() - f.close() + with open(filename, 'rb') as f: + c = f.read() return c body_start_re = re.compile( |