From cff884ccf5709658ee4cd489e63367200b4c86d6 Mon Sep 17 00:00:00 2001 From: jyan1999 Date: Fri, 26 Jan 2024 21:56:57 -0500 Subject: [PATCH] Fixed string encoding error for windows --- src/overcooked_ai_py/mdp/overcooked_env.py | 10 ++++------ testing/overcooked_test.py | 4 ++-- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/overcooked_ai_py/mdp/overcooked_env.py b/src/overcooked_ai_py/mdp/overcooked_env.py index 2b81c580..88634669 100644 --- a/src/overcooked_ai_py/mdp/overcooked_env.py +++ b/src/overcooked_ai_py/mdp/overcooked_env.py @@ -235,9 +235,8 @@ def print_state_transition( if fname is None: print(output_string) else: - f = open(fname, "a") - print(output_string, file=f) - f.close() + with open(fname, "a", encoding='utf-8') as f: + print(output_string, file=f) ################### # BASIC ENV LOGIC # @@ -446,9 +445,8 @@ def run_agents( if dir != None: fname = dir + "/roll_out_" + str(time.time()) + ".txt" - f = open(fname, "w+") - print(self, file=f) - f.close() + with open(fname, "w+", encoding='utf-8') as f: + print(self, file=f) while not done: s_t = self.state diff --git a/testing/overcooked_test.py b/testing/overcooked_test.py index e9677bc3..8eb98bca 100644 --- a/testing/overcooked_test.py +++ b/testing/overcooked_test.py @@ -1323,9 +1323,9 @@ def tearDown(self): shutil.rmtree(self.dummy_dir) def _assert_files_equal(self, file_1, file_2): - with open(file_1, "r") as f: + with open(file_1, "r", encoding='utf-8') as f: lines_1 = f.readlines() - with open(file_2, "r") as f: + with open(file_2, "r", encoding="utf-8") as f: lines_2 = f.readlines() for line_1, line_2 in zip(lines_1, lines_2):