You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

19 lines
445 B

  1. class DictThing:
  2. def __init__(self, init_dict):
  3. self.d = init_dict
  4. def __setattr__(self, name, value):
  5. if name == "d":
  6. super().__setattr__("d", value)
  7. else:
  8. self.d[name] = value
  9. def __getattr__(self, name):
  10. if name == "d":
  11. return super().__getattribute__("d")
  12. return self.d[name]
  13. if __name__ == "__main__":
  14. e = DictThing(dict(a="a", b="b", c="c"))