From 3a7ac51071ad9f3ae277046c29d7482b56754d1d Mon Sep 17 00:00:00 2001 From: ISSOtm Date: Sun, 3 Jun 2018 16:54:29 +0200 Subject: Make coverage script work on Python 2 again I tested using both my Python 2 and Python 3, it worked for both. Worked for me previously because Py3 is my default, not 2 :p --- tools/disasm_coverage.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'tools/disasm_coverage.py') diff --git a/tools/disasm_coverage.py b/tools/disasm_coverage.py index 6c1c030..39d1960 100644 --- a/tools/disasm_coverage.py +++ b/tools/disasm_coverage.py @@ -29,8 +29,13 @@ if __name__ == "__main__": rows_per_bank = bank_size // (width * bpp) r = MapReader() - with open(args.mapfile, 'r', encoding= "utf-8") as f: - l = f.readlines() + try: + with open(args.mapfile, 'r') as f: + l = f.readlines() + except UnicodeDecodeError: + # Python 3 seems to choke on the file's encoding, but the `encoding` keyword only works on Py3 + with open(args.mapfile, 'r', encoding= "utf-8") as f: + l = f.readlines() r.read_map_data(l) hit_data = [[0] * width for _ in range(height)] -- cgit v1.2.3