summaryrefslogtreecommitdiff
path: root/day1
diff options
context:
space:
mode:
authorAndrew <saintruler@gmail.com>2019-03-11 22:39:21 +0400
committerAndrew <saintruler@gmail.com>2019-03-11 22:39:21 +0400
commit093320ae4bc1e62441a8189b4dd84b07f04aae2d (patch)
tree221f669768c5be73db44600b1263e0fa3400ae05 /day1
parent3807ef5eec1fa89f17918096d7a2623cf63deebe (diff)
Еще один раз исправил вторую задачу
Diffstat (limited to 'day1')
-rw-r--r--day1/task2/task2.py38
1 files changed, 22 insertions, 16 deletions
diff --git a/day1/task2/task2.py b/day1/task2/task2.py
index 5a942dd..593df5b 100644
--- a/day1/task2/task2.py
+++ b/day1/task2/task2.py
@@ -1,30 +1,36 @@
import os
+CHUNK_SIZE = 1024
+
write_path = os.path.join(os.getcwd(), 'task2_data_1.txt')
read_path = os.path.join(os.getcwd(), 'task2_data_2.txt')
+try:
+ write_file = open(write_path, 'a')
+ read_file = open(read_path)
+
+except FileNotFoundError as e:
+ exception_path = str(e).strip('[Errno 2] No such file or directory:')[1:-1]
+ print(f'"{exception_path}" не существует')
-if not os.access(write_path, os.F_OK):
- print('Файла "{}" не существует'.format(write_path))
-elif not os.access(read_path, os.F_OK):
- print('Файла "{}" не существует'.format(read_path))
+except PermissionError as e:
+ exception_path = str(e).strip('[Errno 13] Permission denied:')[1:-1]
+ print(f'Файл "{exception_path}" не доступен для чтения/записи')
-elif not os.access(write_path, os.W_OK):
- print('Файл "{}" не доступен для записи'.format(write_path))
-elif not os.access(read_path, os.R_OK):
- print('Файл "{}" не доступен для чтения'.format(read_path))
+except IsADirectoryError as e:
+ exception_path = str(e).strip('[Errno 21] Is a directory:')[1:-1]
+ print(f'"{exception_path}" является директорией')
else:
- with open(write_path, 'a') as first, open(read_path) as second:
- first.write('\n\n\n')
+ write_file.write('\n\n\n')
- data = second.read(1024)
- first.write(data)
- while data:
- data = second.read(1024)
- first.write(data)
+ data = read_file.read(CHUNK_SIZE)
+ write_file.write(data)
+ while data:
+ data = read_file.read(CHUNK_SIZE)
+ write_file.write(data)
+ # пожалуйста не мучайте меня я не хочу писать еще три expept'a
os.rename('task2_data_1.txt', 'task2_data_all.txt')
os.remove('task2_data_2.txt')
-