diff options
| author | Andrew <saintruler@gmail.com> | 2019-03-09 20:40:05 +0400 |
|---|---|---|
| committer | Andrew <saintruler@gmail.com> | 2019-03-09 20:40:05 +0400 |
| commit | 059276bc90a2c402c1d7a4f9b97368f52d29aa40 (patch) | |
| tree | b76da3ac21f6e97059316bf8cf9bd81ad229c994 | |
| parent | 870dd86b9a233d1725b842bdca32db5db135c2af (diff) | |
Дополнена третья задача
| -rw-r--r-- | day1/task3/task3.py | 9 |
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()) |