Creating class instance properties from a dictionary?
You can use setattr (be careful though: not every string is a valid attribute name!): >>> class AllMyFields: … def __init__(self, dictionary): … for k, v in dictionary.items(): … setattr(self, k, v) … >>> o = AllMyFields({‘a’: 1, ‘b’: 2}) >>> o.a 1 Edit: let me explain the difference between the above code and SilentGhost’s … Read more