'''
class python_object:
def __init__(self, id, username, password):
self.id = id
self.username = username
self.password = password
#object_dict is made by importing JSON objects and looks like this
object_dict = {1: <__main__.python_object object at 0x00000283EBD7CEC8>,
2: <__main__.python_object object at 0x00000283EBD7CF08>,
3: <__main__.python_object object at 0x00000283EBD7CF48>,
4: <__main__.python_object object at 0x00000283EBD7CF88>}
#///some other code///
id = "10021"
attribute_to_find = input("Enter an Attribute: ")
for i in range(1, len(object_dict)+1):
if (object_dict.get(i)).id == id_to_find:
print(object_dict.get(i).attribute_to_find)
'''
这不起作用,因为 Python 正在寻找一个名为 'attribute_to_find' 的 'python_object' 的属性,这就是我的想法。
我希望用户能够输入一个属性并让程序打印出类实例中该属性的值,id 为“10021”(“id”是“python_object”的另一个属性)
有谁知道我该怎么做?
谢谢 :)