summaryrefslogtreecommitdiff
path: root/day1/task3
diff options
context:
space:
mode:
authorAndrew <saintruler@gmail.com>2019-03-11 23:06:28 +0400
committerAndrew <saintruler@gmail.com>2019-03-11 23:06:28 +0400
commit0298dd3b5b67ca2b339507d616e86924b940428f (patch)
treeb97744c95fc3e0c5e17dc46c3f5214d701fff37c /day1/task3
parent059276bc90a2c402c1d7a4f9b97368f52d29aa40 (diff)
Исправил третью задачу
Diffstat (limited to 'day1/task3')
-rw-r--r--day1/task3/task3.py29
1 files changed, 18 insertions, 11 deletions
diff --git a/day1/task3/task3.py b/day1/task3/task3.py
index 23c327b..2dae428 100644
--- a/day1/task3/task3.py
+++ b/day1/task3/task3.py
@@ -4,21 +4,28 @@ import os
file_path = input()
if os.access(file_path, os.W_OK):
- print('Файл "{}" существует и доступен для записи. Удаляем...'.format(file_path))
- os.remove(file_path)
+ try:
+ open(file_path)
+ except IsADirectoryError:
+ print(f'Файл "{file_path}" является директорией. Завершаем работу...')
+ else:
+ print(f'Файл "{file_path}" существует и доступен для записи. Удаляем...')
+ os.remove(file_path)
+
else:
try:
- with open(file_path, 'w', encoding='utf-8') as f:
- f.write('Ало здравствуйте. Alo zdravstvuite.')
+ f = open(file_path, 'w', encoding='utf-8')
except PermissionError:
- print('Путь "{}" не доступен для записи.'.format(file_path))
+ print(f'Путь "{file_path}" не доступен для записи.')
print('Завершаем работу...')
- quit()
- with open(file_path, encoding='cp1251') as f:
- print(f.read())
+ else:
+ f.write('Ало здравствуйте. Alo zdravstvuite.')
+
+ with open(file_path, encoding='cp1251') as f:
+ print(f.read())
- with open(file_path, encoding='utf-8') as f:
- print(f.read())
+ with open(file_path, encoding='utf-8') as f:
+ print(f.read())
- os.remove(file_path)
+ os.remove(file_path)