我经常需要做这样的事情:
"Some dictionary with values obtained somehow (e.g. submitted form values)"
my_dict = {
'name': 'John',
'surname': 'Doe',
'age': 27,
'hair_color': 'green',
}
"object person is some instance of class representing person"
person.name = my_dict['name']
person.surname = my_dict['surname']
person.age = my_dict['age']
person.hair_color = my_dict['hair_color']
我认为这是很多重复。你用什么方法?