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 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 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(-) 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 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(+) 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 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(-) 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 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(-) 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