Добавлена функция save_report
This commit is contained in:
parent
794284aa29
commit
abecc37deb
15
zadanie_1.py
15
zadanie_1.py
@ -135,3 +135,18 @@ def generate_report(stats: dict) -> str:
|
||||
|
||||
report_lines.append("=" * 50)
|
||||
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