1class HauntedMansion:
2 def __init__(self, **kwargs):
3 for key, value in kwargs.items():
4 self.__dict__[f"spooky_{key}"] = value
5
6 def __getattr__(self, name):
7 if name[:7] == "spooky_":
8 return self.__dict__.get(name, "Booooo, only ghosts here!")
9 return "Booooo, only ghosts here!"
10
11 def __setattr__(self, name, value):
12 if name[:2] != "__":
13 name = f"spooky_{name}"
14 self.__dict__[name] = value
.
----------------------------------------------------------------------
Ran 1 test in 0.000s
OK