summaryrefslogtreecommitdiff
path: root/day1/task3/task3.py
diff options
context:
space:
mode:
authorAndrew <saintruler@gmail.com>2019-03-09 20:40:05 +0400
committerAndrew <saintruler@gmail.com>2019-03-09 20:40:05 +0400
commit059276bc90a2c402c1d7a4f9b97368f52d29aa40 (patch)
treeb76da3ac21f6e97059316bf8cf9bd81ad229c994 /day1/task3/task3.py
parent870dd86b9a233d1725b842bdca32db5db135c2af (diff)
Дополнена третья задача
Diffstat (limited to 'day1/task3/task3.py')
-rw-r--r--day1/task3/task3.py9
1 files 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())