summaryrefslogtreecommitdiff
path: root/day1/task3
diff options
context:
space:
mode:
Diffstat (limited to 'day1/task3')
-rw-r--r--day1/task3/task3.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/day1/task3/task3.py b/day1/task3/task3.py
new file mode 100644
index 0000000..2dae428
--- /dev/null
+++ b/day1/task3/task3.py
@@ -0,0 +1,31 @@
+import os
+
+
+file_path = input()
+
+if os.access(file_path, os.W_OK):
+ try:
+ open(file_path)
+ except IsADirectoryError:
+ print(f'Файл "{file_path}" является директорией. Завершаем работу...')
+ else:
+ print(f'Файл "{file_path}" существует и доступен для записи. Удаляем...')
+ os.remove(file_path)
+
+else:
+ try:
+ f = open(file_path, 'w', encoding='utf-8')
+ except PermissionError:
+ print(f'Путь "{file_path}" не доступен для записи.')
+ print('Завершаем работу...')
+
+ 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())
+
+ os.remove(file_path)