diff options
-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( |