从字符串值中为现有变量赋值

Assigning Variable with Value of Existing Variable from String Value

我有大量变量形式的数据:

abc_123 = 5  
def_456 = 7  
ghi_789 = 9 

等等

我要求用户提供各种输入,这会构建一个字符串。例如:

temp = "abc_123"

如何使 temp = abc_123,从而使 temp = 5?

创建一个字典,然后按键查找值:

>>> d = {"abc_123": 5, "def_456": 7, "ghi_789": 9}
>>> temp = "abc_123"
>>> d[temp]
5
>>> d.get("invalid", "not found")
'not found'