view.py
variable = 'amount'
amount = 200
print(variable) #actual: 'amount' expected: 200
In such case, is it possible to use Variable Variable like PHP? in php, I could do
$variable = 'amount';
$amount = 200;
echo $$variable;
I know it might be not a good practice, but sometimes it could provide very powerful features.
Thanks.
Variable Variable. But if you want to use string to create variable then use dictionary -name = 'John'variable[name] = namemy_vars = {"name": "John", ...}with as many keys as you want/need, and access it withmy_vars[variable_name]