From: Sebastien Bourdeauducq Date: Wed, 8 Apr 2015 11:41:54 +0000 (+0800) Subject: mibuild/tools/write_to_file: use context manager X-Git-Tag: 24jan2021_ls180~2099^2~121 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=8ce683964ac55cad51e01b5f152f4bbe3a190038;p=litex.git mibuild/tools/write_to_file: use context manager --- diff --git a/mibuild/tools.py b/mibuild/tools.py index 10300443..ab690ed0 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