'Python Update an Object from Dictionary

I have an object User, and I have a dictionary of attributes that needs to be updated like data={'name':"Tom",'age':26} I want to iterate over the dictionary and update it Something like this:

for key,val in data.items():
    user.key=val

The problem is it is saying user have no attribute as key. I want to replace user.key as user.name="Tom"

Any solution to it?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source