From 29eb2d0191876ce939393584d5065a823b6f1e91 Mon Sep 17 00:00:00 2001 From: David Hadka Date: Thu, 5 Sep 2024 15:20:45 +0000 Subject: [PATCH] Use xlsx instead of xls due to Pandas deprecating xls --- .gitignore | 1 + examples/Eijgenraam/eijgenraam_mordm.py | 4 ++-- rhodium/utils.py | 21 +++++++++++---------- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index 52e4b23..7da8e01 100644 --- a/.gitignore +++ b/.gitignore @@ -16,5 +16,6 @@ Rhodium.egg-info/ *.o *.pyc *.so +*.xlsx .Rhistory .DS_Store diff --git a/examples/Eijgenraam/eijgenraam_mordm.py b/examples/Eijgenraam/eijgenraam_mordm.py index 40b747c..b1ca606 100644 --- a/examples/Eijgenraam/eijgenraam_mordm.py +++ b/examples/Eijgenraam/eijgenraam_mordm.py @@ -236,8 +236,8 @@ def find_height(t): ##============================================================================== ## Export the data (Excel, CSV, JSON, pickle) ##------------------------------------------------------------------------------ -if promptToRun("Save policies to Excel (eijgenraam_mordm.xls)?"): - policies.save("eijgenraam_mordm.xls") +if promptToRun("Save policies to Excel (eijgenraam_mordm.xlsx)?"): + policies.save("eijgenraam_mordm.xlsx") ##============================================================================== ## Display all the data in a pretty format diff --git a/rhodium/utils.py b/rhodium/utils.py index 75c0cf7..9e6e2ea 100644 --- a/rhodium/utils.py +++ b/rhodium/utils.py @@ -19,19 +19,20 @@ import sys def promptToRun(message, default="yes"): - if os.getenv("RHODIUM_NO_PROMPT"): - response = "" + if default == "yes": + prompt = "[Y/n]" + elif default == "no": + prompt = "[y/N]" else: - if default == "yes": - prompt = "[Y/n]" - elif default == "no": - prompt = "[y/N]" - else: - raise ValueError("invalid default answer") + raise ValueError("invalid default answer") - print(message + " " + prompt + " ", end='') - sys.stdout.flush() + print(message + " " + prompt + " ", end='') + sys.stdout.flush() + if os.getenv("RHODIUM_NO_PROMPT"): + print("(Skipping prompt since RHODIUM_NO_PROMPT is set)") + response = "" + else: response = sys.stdin.readline().strip() if response == "":