Предизвикателства > Сляпа баба > Решения > Решението на Тихомир Божков

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

1 точки общо

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

 1import secret
 2
 3def methodify():
 4    target_module = secret
 5    faculty_number = "31592"
 6
 7    interesting_methods = []
 8
 9    def find_secret(current_object, current_path):
10        if isinstance(current_object, type):
11            object_methods = [method for method in dir(current_object) if callable(getattr(current_object, method))]
12        else:
13            object_methods = [
14                method
15                for method in dir(current_object)
16                if callable(getattr(current_object, method)) and not method.startswith("__")
17            ]
18
19        for method_name in object_methods:
20            if "clue" in method_name and len(method_name) == 5:
21                full_path = f"{current_path}.{method_name}"
22                interesting_methods.append(full_path)
23
24            attribute = getattr(obj, method_name)
25            if hasattr(attribute, "__dict__"):
26                find_secret(attribute, f"{current_path}.{method_name}")
27
28    find_secret(target_module, "secret")
29
30    faculty_number_str = str(faculty_number).zfill(10)
31    method_names = [f"FN{faculty_number_str[i]}" for i in range(10)]
32
33    result_methods = [method for method in interesting_methods if method.split(".")[-1] in method_names]
34
35    return tuple(result_methods)

E
======================================================================
ERROR: test_metodify (test.TestMethodify)
Test metodify function.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 12, in test_metodify
self.assertIn(methodify(), _RESULTS.keys())
File "/tmp/solution.py", line 28, in methodify
find_secret(target_module, "secret")
File "/tmp/solution.py", line 24, in find_secret
attribute = getattr(obj, method_name)
NameError: name 'obj' is not defined

----------------------------------------------------------------------
Ran 1 test in 0.000s

FAILED (errors=1)

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