Предизвикателства > Haunted mansion > Решения > Решението на Елена Гинкова

Резултати
0 точки от тестове
0 точки от учител

0 точки общо

0 успешни теста
1 неуспешни теста
Код

 1class HauntedMansion(dict):
 2   
 3    def __init__(self, **kwargs):
 4        for key, val in kwargs.items(): 
 5            setattr(self, key, val)
 6    def __getattribute__(self, name):
 7        if(name[:len("spooky_")] == "spooky_"):
 8            spooky_name = name[len("spooky_"):]
 9            return object.__getattribute__(self, spooky_name)
10        elif name[2:] == "__" and name[:len(name) - 3] == "__":
11            return object.__getattribute__(self, name)
12        else:
13            return "Booooo, only ghosts here!"   

E
======================================================================
ERROR: test_haunted_mansion (test.TestHauntedMansion.test_haunted_mansion)
The mansion should be really spooky and haunted.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 25, in test_haunted_mansion
self.assertEqual(haunted_mansion.spooky_buttler, "Booooo, only ghosts here!")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/solution.py", line 9, in __getattribute__
return object.__getattribute__(self, spooky_name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'HauntedMansion' object has no attribute 'buttler'

----------------------------------------------------------------------
Ran 1 test in 0.001s

FAILED (errors=1)

Дискусия
История
Това решение има само една версия.