From 059276bc90a2c402c1d7a4f9b97368f52d29aa40 Mon Sep 17 00:00:00 2001 From: Andrew Date: Sat, 9 Mar 2019 20:40:05 +0400 Subject: =?UTF-8?q?=D0=94=D0=BE=D0=BF=D0=BE=D0=BB=D0=BD=D0=B5=D0=BD=D0=B0?= =?UTF-8?q?=20=D1=82=D1=80=D0=B5=D1=82=D1=8C=D1=8F=20=D0=B7=D0=B0=D0=B4?= =?UTF-8?q?=D0=B0=D1=87=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- day1/task3/task3.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/day1/task3/task3.py b/day1/task3/task3.py index b046ad2..23c327b 100644 --- a/day1/task3/task3.py +++ b/day1/task3/task3.py @@ -7,8 +7,13 @@ if os.access(file_path, os.W_OK): print('Файл "{}" существует и доступен для записи. Удаляем...'.format(file_path)) os.remove(file_path) else: - with open(file_path, 'w', encoding='utf-8') as f: - f.write('Ало здравствуйте. Alo zdravstvuite.') + 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()) -- cgit v1.2.3