attr_from_string.py 200 B

1234567891011
  1. class Test():
  2. def __init__(self):
  3. self.val = None
  4. def setByString(self, string, value):
  5. self.__dict__[string] = value
  6. t = Test()
  7. t.setByString('val', 1)
  8. print t.__dict__