From 8ce683964ac55cad51e01b5f152f4bbe3a190038 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Wed, 8 Apr 2015 19:41:54 +0800 Subject: [PATCH] mibuild/tools/write_to_file: use context manager --- mibuild/tools.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/mibuild/tools.py b/mibuild/tools.py index 103004435..ab690ed06 100644 --- a/mibuild/tools.py +++ b/mibuild/tools.py @@ -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