Добавлена функция save_report
This commit is contained in:
parent
794284aa29
commit
abecc37deb
17
zadanie_1.py
17
zadanie_1.py
@ -134,4 +134,19 @@ def generate_report(stats: dict) -> str:
|
|||||||
report_lines.append(f" - {item}")
|
report_lines.append(f" - {item}")
|
||||||
|
|
||||||
report_lines.append("=" * 50)
|
report_lines.append("=" * 50)
|
||||||
return "\n".join(report_lines)
|
return "\n".join(report_lines)
|
||||||
|
|
||||||
|
|
||||||
|
# 10. Сохранение отчета в файл
|
||||||
|
def save_report(filepath: str, report_text: str) -> bool:
|
||||||
|
"""
|
||||||
|
Сохраняет отчет в файл. Возвращает True при успехе.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
os.makedirs(os.path.dirname(filepath), exist_ok=True)
|
||||||
|
with open(filepath, 'w', encoding='utf-8') as file:
|
||||||
|
file.write(report_text)
|
||||||
|
return True
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Ошибка при сохранении отчета: {e}")
|
||||||
|
return False
|
||||||
Loading…
Reference in New Issue
Block a user