Together_Project/script_work_with_files.py

20 lines
744 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# script.py
try:
# Чтение данных с указанием кодировки
with open('data.txt', 'r', encoding='utf-8') as f_in:
lines = [line.strip() for line in f_in.readlines()]
# Преобразование с учётом русских букв
processed_data = [line.upper() for line in lines]
# Запись с сохранением кириллицы
with open('output.txt', 'w', encoding='utf-8') as f_out:
f_out.write('\n'.join(processed_data))
print("Данные обработаны! Результат в output.txt")
except FileNotFoundError:
print("Ошибка: Файл data.txt не найден!")
except Exception as e:
print(f"Ошибка: {str(e)}")