diff options
| author | Андрей Гущин <saintruler@gmail.com> | 2019-03-15 19:32:55 +0300 |
|---|---|---|
| committer | Андрей Гущин <saintruler@gmail.com> | 2019-03-15 19:32:55 +0300 |
| commit | 963fab279d069a57ba14e8d77677840272e8c071 (patch) | |
| tree | d1b5599abb4e048b5f98b1de17ae2eb643c9a26c /day1/task2/task2.py | |
| parent | 8916d790f44b95a60fd7ee3001c9e97b703f7ae0 (diff) | |
| parent | 92b7d6c7b75aa4a6d6a2edc12f76cb45a4d06528 (diff) | |
Merge branch 'master' into 'day1_task1'
# Conflicts:
# .gitignore
Diffstat (limited to 'day1/task2/task2.py')
| -rw-r--r-- | day1/task2/task2.py | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/day1/task2/task2.py b/day1/task2/task2.py new file mode 100644 index 0000000..593df5b --- /dev/null +++ b/day1/task2/task2.py @@ -0,0 +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}" не существует') + +except PermissionError as e: + exception_path = str(e).strip('[Errno 13] Permission denied:')[1:-1] + print(f'Файл "{exception_path}" не доступен для чтения/записи') + +except IsADirectoryError as e: + exception_path = str(e).strip('[Errno 21] Is a directory:')[1:-1] + print(f'"{exception_path}" является директорией') + +else: + write_file.write('\n\n\n') + + 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') |