diff --git a/artiq/frontend/artiq_flash.py b/artiq/frontend/artiq_flash.py index 8c0090187..b43ee473b 100755 --- a/artiq/frontend/artiq_flash.py +++ b/artiq/frontend/artiq_flash.py @@ -97,7 +97,8 @@ def main(): elif action == "gateware": bin = os.path.join(opts.dir, "top.bin") if not os.access(bin, os.R_OK): - bin = tempfile.mkstemp()[1] + bin_handle, bin = tempfile.mkstemp() + bin_handle.close() bit = os.path.join(opts.dir, "top.bit") conv = True prog.append("jtagspi_program {} 0x{:x}".format( diff --git a/artiq/frontend/bit2bin.py b/artiq/frontend/bit2bin.py index a537fc209..ded87a0b3 100755 --- a/artiq/frontend/bit2bin.py +++ b/artiq/frontend/bit2bin.py @@ -60,7 +60,8 @@ def bit2bin(bit, bin, flip=False): d = bitfile.read(l) if flip: d = flip32(d) - open(bin, "wb").write(d) + with open(bin, "wb") as f: + f.write(d) else: d = bitfile.read(*struct.unpack(">H", bitfile.read(2))) print("Unexpected key: ", key, d)