1class HauntedMansion:
2 def __init__(self, **kwargs):
3 for key,value in kwargs.items():
4 setattr(self, key, value)
5
6 def __setattr__(self, name, value):
7 object.__setattr__(self, 'spooky_' + name, value)
8
9 def __getattr__(self, name):
10 return 'Booooo, only ghosts here!'
.
----------------------------------------------------------------------
Ran 1 test in 0.000s
OK
t | 1 | class HantedMansion: | t | 1 | class HauntedMansion: |
2 | def __init__(self, **kwargs): | 2 | def __init__(self, **kwargs): | ||
3 | for key,value in kwargs.items(): | 3 | for key,value in kwargs.items(): | ||
4 | setattr(self, key, value) | 4 | setattr(self, key, value) | ||
5 | 5 | ||||
6 | def __setattr__(self, name, value): | 6 | def __setattr__(self, name, value): | ||
7 | object.__setattr__(self, 'spooky_' + name, value) | 7 | object.__setattr__(self, 'spooky_' + name, value) | ||
8 | 8 | ||||
9 | def __getattr__(self, name): | 9 | def __getattr__(self, name): | ||
10 | return 'Booooo, only ghosts here!' | 10 | return 'Booooo, only ghosts here!' | ||
11 | 11 |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|