From 645bc7723c355a819bc8681c561f32c3757a59ba Mon Sep 17 00:00:00 2001 From: Andrew Date: Mon, 4 Mar 2019 20:01:10 +0400 Subject: Day 1 Task 2 --- day1/task2/task2.py | 11 +++++++++++ day1/task2/task2_data_1.txt | 1 + day1/task2/task2_data_2.txt | 4 ++++ 3 files changed, 16 insertions(+) create mode 100644 day1/task2/task2.py create mode 100644 day1/task2/task2_data_1.txt create mode 100644 day1/task2/task2_data_2.txt (limited to 'day1') diff --git a/day1/task2/task2.py b/day1/task2/task2.py new file mode 100644 index 0000000..5f85953 --- /dev/null +++ b/day1/task2/task2.py @@ -0,0 +1,11 @@ +import os + + +with open('task2_data_1.txt', 'a') as first, open('task2_data_2.txt') as second: + second_data = second.read() + first.write('\n\n\n') + first.write(second_data) + +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 -- cgit v1.2.3 From 7e551b94d0b9bf10ae1def6123e1389962893a2f Mon Sep 17 00:00:00 2001 From: Andrew Date: Mon, 4 Mar 2019 20:02:20 +0400 Subject: Day 1 Task 3 --- day1/task3/task3.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 day1/task3/task3.py (limited to 'day1') diff --git a/day1/task3/task3.py b/day1/task3/task3.py new file mode 100644 index 0000000..a456af9 --- /dev/null +++ b/day1/task3/task3.py @@ -0,0 +1,18 @@ +import os + + +file_path = input() + +if os.access(file_path, os.W_OK): + os.remove(file_path) +else: + with open(file_path, 'w', encoding='utf-8') as f: + f.write('Ало здравствуйте. Alo zdravstvuite.') + + with open(file_path, 'w', encoding='windows-1251') as f: + print(f.read()) + + with open(file_path, 'w', encoding='utf-8') as f: + print(f.read()) + + os.remove(file_path) -- cgit v1.2.3 From ddd5bfe49f1b9c3dfb3b1b448bece9fc636cb88f Mon Sep 17 00:00:00 2001 From: Andrew Date: Mon, 4 Mar 2019 20:03:49 +0400 Subject: Day 1 Task 4 --- day1/task4/task4.py | 25 +++++++++++++++++++++++++ day1/task4/task4_data.html | 13 +++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 day1/task4/task4.py create mode 100644 day1/task4/task4_data.html (limited to 'day1') diff --git a/day1/task4/task4.py b/day1/task4/task4.py new file mode 100644 index 0000000..9ed9f2d --- /dev/null +++ b/day1/task4/task4.py @@ -0,0 +1,25 @@ +import string +import re +import os + +with open('task4_data.html') as f: + data = f.read() + +# Не знаю зачем, но в задании так написано +os.chdir('..') +os.mkdir('htmls') +os.chdir('htmls') + +cleared_data = ''.join(filter(lambda char: char in string.printable, data)) +with open('ascii_cleared.html', 'w', encoding='utf-8') as f: + f.write(cleared_data) + +body_cleared = re.sub( + r'(.|\n)*?', + lambda match: match.string[match.start(): match.end()].replace('\n', ''), + data +) + +with open('body_cleared.html', 'w', encoding='utf-8') as f: + f.write(body_cleared) + diff --git a/day1/task4/task4_data.html b/day1/task4/task4_data.html new file mode 100644 index 0000000..4357c07 --- /dev/null +++ b/day1/task4/task4_data.html @@ -0,0 +1,13 @@ + + + + + A Small Hello. Это по идеи заголовок. + + + +

Hi я интерактивная страница

+

I want to be inline, in my source code

+

This is very minimal "hello world" HTML document.

+ + -- cgit v1.2.3 From 82383dcaaf1fc3eebe6b6b27565106013ab7d851 Mon Sep 17 00:00:00 2001 From: Andrew Date: Mon, 4 Mar 2019 20:08:48 +0400 Subject: Day 1 Task 5 --- day1/task5/task5.py | 15 +++++++++++++++ day1/task5/task5_data.txt | 1 + 2 files changed, 16 insertions(+) create mode 100644 day1/task5/task5.py create mode 100644 day1/task5/task5_data.txt (limited to 'day1') diff --git a/day1/task5/task5.py b/day1/task5/task5.py new file mode 100644 index 0000000..52eafc2 --- /dev/null +++ b/day1/task5/task5.py @@ -0,0 +1,15 @@ +with open('task5_data.txt') as f: + print(f.read()) + +with open('task5_data.txt', 'rb+') as input_byte, open('task5_data_new.txt', 'wb') as out: + char = input_byte.read(1) + while char: + binary = list(bin(int(char.hex(), 16))[2:]) + if binary[-2] == '1': + binary[-2] = '0' + elif binary[-2] == '0': + binary[-2] = '1' + + out.write(bytes([int(''.join(binary), 2)])) + char = input_byte.read(1) + diff --git a/day1/task5/task5_data.txt b/day1/task5/task5_data.txt new file mode 100644 index 0000000..0808eaa --- /dev/null +++ b/day1/task5/task5_data.txt @@ -0,0 +1 @@ +12йцas -- cgit v1.2.3 From ca19bb3090829b64b04a0814d223f03e4693f13f Mon Sep 17 00:00:00 2001 From: Andrew Date: Mon, 4 Mar 2019 20:59:43 +0400 Subject: Task 3 fixed --- day1/task3/task3.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'day1') diff --git a/day1/task3/task3.py b/day1/task3/task3.py index a456af9..6d328ac 100644 --- a/day1/task3/task3.py +++ b/day1/task3/task3.py @@ -9,10 +9,10 @@ else: with open(file_path, 'w', encoding='utf-8') as f: f.write('Ало здравствуйте. Alo zdravstvuite.') - with open(file_path, 'w', encoding='windows-1251') as f: + with open(file_path, encoding='cp1251') as f: print(f.read()) - with open(file_path, 'w', encoding='utf-8') as f: + with open(file_path, encoding='utf-8') as f: print(f.read()) os.remove(file_path) -- cgit v1.2.3 From 3807ef5eec1fa89f17918096d7a2623cf63deebe Mon Sep 17 00:00:00 2001 From: Andrew Date: Sat, 9 Mar 2019 20:00:35 +0400 Subject: =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD?= =?UTF-8?q?=D0=B0=20=D0=B2=D1=82=D0=BE=D1=80=D0=B0=D1=8F=20=D0=B7=D0=B0?= =?UTF-8?q?=D0=B4=D0=B0=D1=87=D0=B0=20=D0=BF=D0=B5=D1=80=D0=B2=D0=BE=D0=B3?= =?UTF-8?q?=D0=BE=20=D0=B4=D0=BD=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- day1/task2/task2.py | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) (limited to 'day1') diff --git a/day1/task2/task2.py b/day1/task2/task2.py index 5f85953..5a942dd 100644 --- a/day1/task2/task2.py +++ b/day1/task2/task2.py @@ -1,11 +1,30 @@ import os -with open('task2_data_1.txt', 'a') as first, open('task2_data_2.txt') as second: - second_data = second.read() - first.write('\n\n\n') - first.write(second_data) +write_path = os.path.join(os.getcwd(), 'task2_data_1.txt') +read_path = os.path.join(os.getcwd(), 'task2_data_2.txt') -os.rename('task2_data_1.txt', 'task2_data_all.txt') -os.remove('task2_data_2.txt') + +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)) + +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)) + +else: + with open(write_path, 'a') as first, open(read_path) as second: + first.write('\n\n\n') + + data = second.read(1024) + first.write(data) + while data: + data = second.read(1024) + first.write(data) + + os.rename('task2_data_1.txt', 'task2_data_all.txt') + os.remove('task2_data_2.txt') -- cgit v1.2.3 From 870dd86b9a233d1725b842bdca32db5db135c2af Mon Sep 17 00:00:00 2001 From: Andrew Date: Sat, 9 Mar 2019 20:12:27 +0400 Subject: =?UTF-8?q?=D0=94=D0=BE=D0=BF=D0=BE=D0=BB=D0=BD=D0=B5=D0=BD=D0=B0?= =?UTF-8?q?=20=D1=82=D1=80=D0=B5=D1=82=D1=8C=D1=8F=20=D0=B7=D0=B0=D0=B4?= =?UTF-8?q?=D0=B0=D1=87=D0=B0=20=D0=BF=D0=B5=D1=80=D0=B2=D0=BE=D0=B3=D0=BE?= =?UTF-8?q?=20=D0=B4=D0=BD=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- day1/task3/task3.py | 1 + 1 file changed, 1 insertion(+) (limited to 'day1') diff --git a/day1/task3/task3.py b/day1/task3/task3.py index 6d328ac..b046ad2 100644 --- a/day1/task3/task3.py +++ b/day1/task3/task3.py @@ -4,6 +4,7 @@ import os file_path = input() if os.access(file_path, os.W_OK): + print('Файл "{}" существует и доступен для записи. Удаляем...'.format(file_path)) os.remove(file_path) else: with open(file_path, 'w', encoding='utf-8') as f: -- cgit v1.2.3 From 19c117c32bf7de16f86a45b62182c9fae9ef9374 Mon Sep 17 00:00:00 2001 From: Andrew Date: Sat, 9 Mar 2019 20:37:24 +0400 Subject: =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB=D0=B5=D0=BB?= =?UTF-8?q?=D0=B0=20=D1=87=D0=B5=D1=82=D0=B2=D0=B5=D1=80=D1=82=D0=B0=D1=8F?= =?UTF-8?q?=20=D0=B7=D0=B0=D0=B4=D0=B0=D1=87=D0=B0=20=D0=BF=D0=B5=D1=80?= =?UTF-8?q?=D0=B2=D0=BE=D0=B3=D0=BE=20=D0=B4=D0=BD=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- day1/task4/task4.py | 46 ++++++++++++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 16 deletions(-) (limited to 'day1') diff --git a/day1/task4/task4.py b/day1/task4/task4.py index 9ed9f2d..0fcf928 100644 --- a/day1/task4/task4.py +++ b/day1/task4/task4.py @@ -2,24 +2,38 @@ import string import re import os -with open('task4_data.html') as f: - data = f.read() -# Не знаю зачем, но в задании так написано -os.chdir('..') -os.mkdir('htmls') -os.chdir('htmls') +html_path = os.path.join(os.getcwd(), 'task4_data.html') -cleared_data = ''.join(filter(lambda char: char in string.printable, data)) -with open('ascii_cleared.html', 'w', encoding='utf-8') as f: - f.write(cleared_data) +if os.access(html_path, os.R_OK): + with open(html_path) as f: + data = f.read() -body_cleared = re.sub( - r'(.|\n)*?', - lambda match: match.string[match.start(): match.end()].replace('\n', ''), - data -) + # Не знаю зачем, но в задании так написано + try: + os.mkdir('../htmls') + os.chdir('../htmls') + except PermissionError: + print('Директория на уровень выше не доступна для записи.') + print('Создаем папку в текущей директории...') + try: + os.mkdir('htmls') + except PermissionError: + print('Текущая директория не доступна для записи. Завершаем работу...') + quit() -with open('body_cleared.html', 'w', encoding='utf-8') as f: - f.write(body_cleared) + cleared_data = ''.join(filter(lambda char: char in string.printable, data)) + with open('ascii_cleared.html', 'w', encoding='utf-8') as f: + f.write(cleared_data) + body_cleared = re.sub( + r'(.|\n)*?', + lambda match: match.string[match.start(): match.end()].replace('\n', ''), + data + ) + + with open('body_cleared.html', 'w', encoding='utf-8') as f: + f.write(body_cleared) + +else: + print('Файл "{}" не доступен для чтения'.format(html_path)) -- cgit v1.2.3 From 059276bc90a2c402c1d7a4f9b97368f52d29aa40 Mon Sep 17 00:00:00 2001 From: Andrew Date: Sat, 9 Mar 2019 20:40:05 +0400 Subject: =?UTF-8?q?=D0=94=D0=BE=D0=BF=D0=BE=D0=BB=D0=BD=D0=B5=D0=BD=D0=B0?= =?UTF-8?q?=20=D1=82=D1=80=D0=B5=D1=82=D1=8C=D1=8F=20=D0=B7=D0=B0=D0=B4?= =?UTF-8?q?=D0=B0=D1=87=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- day1/task3/task3.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'day1') diff --git a/day1/task3/task3.py b/day1/task3/task3.py index b046ad2..23c327b 100644 --- a/day1/task3/task3.py +++ b/day1/task3/task3.py @@ -7,8 +7,13 @@ if os.access(file_path, os.W_OK): print('Файл "{}" существует и доступен для записи. Удаляем...'.format(file_path)) os.remove(file_path) else: - with open(file_path, 'w', encoding='utf-8') as f: - f.write('Ало здравствуйте. Alo zdravstvuite.') + try: + with open(file_path, 'w', encoding='utf-8') as f: + f.write('Ало здравствуйте. Alo zdravstvuite.') + except PermissionError: + print('Путь "{}" не доступен для записи.'.format(file_path)) + print('Завершаем работу...') + quit() with open(file_path, encoding='cp1251') as f: print(f.read()) -- cgit v1.2.3 From 8d49433235daa0ca3e7ad1b330e4215ee86f4f51 Mon Sep 17 00:00:00 2001 From: Andrew Date: Sat, 9 Mar 2019 20:52:00 +0400 Subject: =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD?= =?UTF-8?q?=D0=B0=20=D0=BF=D1=8F=D1=82=D0=B0=D1=8F=20=D0=B7=D0=B0=D0=B4?= =?UTF-8?q?=D0=B0=D1=87=D0=B0=20=D0=BF=D0=B5=D1=80=D0=B2=D0=BE=D0=B3=D0=BE?= =?UTF-8?q?=20=D0=B4=D0=BD=D1=8F,=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0?= =?UTF-8?q?=20=D1=81=20=D0=B1=D0=B0=D0=B9=D1=82=D0=B0=D0=BC=D0=B8=20=D0=B8?= =?UTF-8?q?=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD=D0=B0=20=D0=BD=D0=B0=20?= =?UTF-8?q?=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D1=83=20=D1=81=20=D1=87=D0=B8?= =?UTF-8?q?=D1=81=D0=BB=D0=B0=D0=BC=D0=B8=20=D0=B2=D0=BC=D0=B5=D1=81=D1=82?= =?UTF-8?q?=D0=BE=20=D1=81=D1=82=D1=80=D0=BE=D0=BA.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- day1/task5/task5.py | 33 +++++++++++++++++++-------------- day1/task5/task5_data.txt | 2 +- 2 files changed, 20 insertions(+), 15 deletions(-) (limited to 'day1') diff --git a/day1/task5/task5.py b/day1/task5/task5.py index 52eafc2..2869247 100644 --- a/day1/task5/task5.py +++ b/day1/task5/task5.py @@ -1,15 +1,20 @@ -with open('task5_data.txt') as f: - print(f.read()) - -with open('task5_data.txt', 'rb+') as input_byte, open('task5_data_new.txt', 'wb') as out: - char = input_byte.read(1) - while char: - binary = list(bin(int(char.hex(), 16))[2:]) - if binary[-2] == '1': - binary[-2] = '0' - elif binary[-2] == '0': - binary[-2] = '1' - - out.write(bytes([int(''.join(binary), 2)])) - char = input_byte.read(1) +import os + +read_path = os.path.join(os.getcwd(), 'task5_data.txt') +write_path = os.path.join(os.getcwd(), 'task5_data_new.txt') + +if not os.access(read_path, os.R_OK): + print('Файл "{}" не доступен для чтения'.format(read_path)) +elif not os.access(write_path, os.W_OK): + print('Файл "{}" не доступен для записи'.format(write_path)) +else: + with open(read_path) as f: + print(f.read()) + + with open('task5_data.txt', 'rb') as input_byte, open(write_path, 'wb') as out: + char = input_byte.read(1) + while char: + number = int(char.hex(), 16) + out.write(bytes([number ^ 2])) + char = input_byte.read(1) diff --git a/day1/task5/task5_data.txt b/day1/task5/task5_data.txt index 0808eaa..2dfc0ba 100644 --- a/day1/task5/task5_data.txt +++ b/day1/task5/task5_data.txt @@ -1 +1 @@ -12йцas +12йцas \ No newline at end of file -- cgit v1.2.3 From 093320ae4bc1e62441a8189b4dd84b07f04aae2d Mon Sep 17 00:00:00 2001 From: Andrew Date: Mon, 11 Mar 2019 22:39:21 +0400 Subject: =?UTF-8?q?=D0=95=D1=89=D0=B5=20=D0=BE=D0=B4=D0=B8=D0=BD=20=D1=80?= =?UTF-8?q?=D0=B0=D0=B7=20=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=B8=D0=BB?= =?UTF-8?q?=20=D0=B2=D1=82=D0=BE=D1=80=D1=83=D1=8E=20=D0=B7=D0=B0=D0=B4?= =?UTF-8?q?=D0=B0=D1=87=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- day1/task2/task2.py | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) (limited to 'day1') 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') - -- cgit v1.2.3 From 5e4ba61600e76d6abab144767312fdf19663f373 Mon Sep 17 00:00:00 2001 From: Andrew Date: Mon, 11 Mar 2019 22:54:30 +0400 Subject: =?UTF-8?q?=D0=9F=D0=BE=D1=87=D0=B8=D0=BD=D0=B8=D0=BB=20=D1=87?= =?UTF-8?q?=D0=B5=D1=82=D0=B2=D0=B5=D1=80=D1=82=D1=83=D1=8E=20=D0=B7=D0=B0?= =?UTF-8?q?=D0=B4=D0=B0=D1=87=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- day1/task4/task4.py | 61 +++++++++++++++++++++++++++++++++++------------------ 1 file changed, 41 insertions(+), 20 deletions(-) (limited to 'day1') diff --git a/day1/task4/task4.py b/day1/task4/task4.py index 0fcf928..2583cb4 100644 --- a/day1/task4/task4.py +++ b/day1/task4/task4.py @@ -5,26 +5,47 @@ import os html_path = os.path.join(os.getcwd(), 'task4_data.html') -if os.access(html_path, os.R_OK): - with open(html_path) as f: - data = f.read() - - # Не знаю зачем, но в задании так написано +folder_path = '' + +# Не знаю зачем, но в задании так написано +try: + os.mkdir('../htmls') + folder_path = '../htmls' +except PermissionError: + print('Директория на уровень выше не доступна для записи.') + print('Создаем папку в текущей директории...') try: - os.mkdir('../htmls') - os.chdir('../htmls') + os.mkdir('htmls') + folder_path = 'htmls' except PermissionError: - print('Директория на уровень выше не доступна для записи.') - print('Создаем папку в текущей директории...') - try: - os.mkdir('htmls') - except PermissionError: - print('Текущая директория не доступна для записи. Завершаем работу...') - quit() + print('Текущая директория не доступна для записи. Завершаем работу...') + quit() + +try: + html_file = open(html_path) + os.chdir(folder_path) + ascii_file = open('ascii_cleared.html', 'w', encoding='utf-8') + body_file = open('body_cleared.html', 'w', encoding='utf-8') + +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: + data = html_file.read() cleared_data = ''.join(filter(lambda char: char in string.printable, data)) - with open('ascii_cleared.html', 'w', encoding='utf-8') as f: - f.write(cleared_data) + ascii_file.write(cleared_data) + + ################### body_cleared = re.sub( r'(.|\n)*?', @@ -32,8 +53,8 @@ if os.access(html_path, os.R_OK): data ) - with open('body_cleared.html', 'w', encoding='utf-8') as f: - f.write(body_cleared) + body_file.write(body_cleared) -else: - print('Файл "{}" не доступен для чтения'.format(html_path)) + html_file.close() + ascii_file.close() + body_file.close() -- cgit v1.2.3 From 0298dd3b5b67ca2b339507d616e86924b940428f Mon Sep 17 00:00:00 2001 From: Andrew Date: Mon, 11 Mar 2019 23:06:28 +0400 Subject: =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D1=82=D1=80=D0=B5=D1=82=D1=8C=D1=8E=20=D0=B7=D0=B0=D0=B4=D0=B0?= =?UTF-8?q?=D1=87=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- day1/task3/task3.py | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) (limited to 'day1') 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) -- cgit v1.2.3