Set attributes from dictionary in python
- by Oscar Reyes
Is it possible to create an object from a dictionary in python in such a way that each key is an attribute of that object?
Something like this:
dict = { 'name': 'Oscar', 'lastName': 'Reyes', 'age':32 }
e = Employee( dict )
print e.name # Oscar
print e.age + 10 # 42
I think it would be pretty much the inverse of this question: Python dictionary from an object's fields