I have a list for variables of fruits in a python script:
VariableScript.py:
variableColorApple = "Red"
variableWeightApple = ["5", "6", "7"]
variablePriceApple = ["10", "15", "20"]
variableColorApple = "Orange"
variableWeightOrange =["8", "9", "10"]
variablePriceOrange =["10", "15", "20"]
#...
And I have another script, where I use user input (user's fruit choice), to run my analysis. I want to write only one script that I can runregardless of the user's fruit selection. So I could avoid if else statements and long scripts.
I thought I could use string operators to import variables, but with string operators python doesn't find the variable in VariableScript module. What else I can try?
I have also already tried operator.getattr(). But then I couldnt access the items in the gettattr().
Just to keep it simple and executable: Let's say the users' input is "Apple" and I just want to print the color of apple from VariablesScript.py. My code is:
from VariableScript import VariablesScript as Variables
userInput = "Apple"
print(Variables.variableColor + UserInput)`
Any idea how can I get the color or apple without actually writing apple?...