diff options
| author | Андрей Гущин <saintruler@gmail.com> | 2019-03-15 19:32:16 +0300 |
|---|---|---|
| committer | Андрей Гущин <saintruler@gmail.com> | 2019-03-15 19:32:16 +0300 |
| commit | 3c461a4190135e070b50cfad12da2532095392fe (patch) | |
| tree | 06a6542acacec165b58cd59105e15bd2218b04d6 /day1/task2 | |
| parent | 7a5d1a5ad9e4369b1e5ae0332fbce94051944f37 (diff) | |
| parent | 093320ae4bc1e62441a8189b4dd84b07f04aae2d (diff) | |
Merge branch 'day1_task2' into 'master'
Day 1 Task 2
See merge request saintruler/trainee!2
Diffstat (limited to 'day1/task2')
| -rw-r--r-- | day1/task2/task2.py | 36 | ||||
| -rw-r--r-- | day1/task2/task2_data_1.txt | 1 | ||||
| -rw-r--r-- | day1/task2/task2_data_2.txt | 4 |
3 files changed, 41 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') diff --git a/day1/task2/task2_data_1.txt b/day1/task2/task2_data_1.txt new file mode 100644 index 0000000..60a2f18 --- /dev/null +++ b/day1/task2/task2_data_1.txt @@ -0,0 +1 @@ +khasdjkgkjdasghdsajkfvadskghha diff --git a/day1/task2/task2_data_2.txt b/day1/task2/task2_data_2.txt new file mode 100644 index 0000000..ae1e9a8 --- /dev/null +++ b/day1/task2/task2_data_2.txt @@ -0,0 +1,4 @@ +f;ldasjgkjasdngjasdbjklfkaSMGG' +ASDDGN +DPAJGN +FKLADSKF'ADSNLGNADSL;JGLJ |