I receive scenario data (identical sets of variables with different values by scenario) in the form of python modules.
Example:
scen00.py
:
scenario_name = ["foo"]
scenario_num = [0]
.
.
scen01.py
:
scenario_name = ["bar"]
scenario_num = [1]
.
.
I import each scenario to a separate incidence of a python function using import as
, and then do all of the programming, referencing the base namespace.
Example:
import sys
def main():
script = sys.argv[0]
no_scens = int(sys.argv[1])
for i in range(0, no_scens):
process_1(i)
def process_1(scen_count):
if scen_count == 0:
import scen00
elif scen_count == 1:
import scen01 as scen00
print(scen00.scenario_name[0], scen00.scenario_num[0])
Expected Outcome:
foo 0
bar 1
While this code works when no_scens
is 2
, the segment in process_1()
which assigns the different scenarios to scen00
is not scalable and inelegant. Assuming I now have 150 scenarios to import, how could I best modify process_1()
?