class Test(): def __init__(self): self.val = None def setByString(self, string, value): self.__dict__[string] = value t = Test() t.setByString('val', 1) print t.__dict__