mibuild/tools/write_to_file: use context manager
authorSebastien Bourdeauducq <sb@m-labs.hk>
Wed, 8 Apr 2015 11:41:54 +0000 (19:41 +0800)
committerSebastien Bourdeauducq <sb@m-labs.hk>
Wed, 8 Apr 2015 11:41:54 +0000 (19:41 +0800)
mibuild/tools.py

index 103004435bb1edf33ea514298130e19d79fbb29b..ab690ed06b0db54e22c5dfe9bfde346fe5858a10 100644 (file)
@@ -19,9 +19,8 @@ def write_to_file(filename, contents, force_unix=False):
        newline = None
        if force_unix:
                newline = "\n"
-       f = open(filename, "w", newline=newline)
-       f.write(contents)
-       f.close()
+       with open(filename, "w", newline=newline) as f:
+               f.write(contents)
 
 def arch_bits():
        return struct.calcsize("P")*8