I have encountered a problem when putting all the modules I've developed into the main program. The switch dictionary I've created can be seen below:
def Tank_Shape_Calcs(Tank_Shape, level, area, dish, radius, length, Strapping_Table, Tank_Number):
switcher = {
0: vertical.Vertical_Tank(level, area),
1: horiz.Horiz_Cylinder_Dished_Ends(dish, radius, level, length),
2: strapping.Calc_Strapped_Volume(Strapping_Table, level),
3: poly.Fifth_Poly_Calcs(Tank_Number)
}
return switcher.get(Tank_Shape, "ERROR: Tank type not valid")
The tank shape is set in the main file in a loop for each of the tanks. The first tank has Tank_Shape = 2
so I would expect it to execute the Calc_Strapped_Volume()
function.
I have tried testing it, and the switcher function is definitely reading Tank_Shape
as 2
. Also if I change the functions to strings, it will print out the correct string.
The problem is that the functions seem to be executed sequentially, until the correct function is called. This results in errors as the data I'm using will only work with the correct function.
Is there a way to only execute the correct function?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…