summaryrefslogtreecommitdiff
path: root/day1/task3/task3.py
blob: 23c327bd3afd549271131e0a57cfaa582a1ff8cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import os


file_path = input()

if os.access(file_path, os.W_OK):
    print('Файл "{}" существует и доступен для записи. Удаляем...'.format(file_path))
    os.remove(file_path)
else:
    try:
        with open(file_path, 'w', encoding='utf-8') as f:
            f.write('Ало здравствуйте. Alo zdravstvuite.')
    except PermissionError:
        print('Путь "{}" не доступен для записи.'.format(file_path))
        print('Завершаем работу...')
        quit()

    with open(file_path, encoding='cp1251') as f:
        print(f.read())

    with open(file_path, encoding='utf-8') as f:
        print(f.read())

    os.remove(file_path)