diff --git a/hw_Lesson_01/1.py b/hw_Lesson_01/1.py new file mode 100644 index 0000000..38a4922 --- /dev/null +++ b/hw_Lesson_01/1.py @@ -0,0 +1,14 @@ +str_1 = "разработка" +str_2 = "сокет" +str_3 = "декоратор" + +print(str_1, type(str_1)) +print(str_2, type(str_2)) +print(str_3, type(str_3)) + +bstr_1 = b'\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0430' # получено в branah.com, в поле utf-16 +print(bstr_1.decode("utf-16"), type(bstr_1)) # почему-то выводит кривые символы +bstr_2 = b'\u0441\u043e\u043a\u0435\u0442' +print(bstr_2.decode("utf-16"), type(bstr_2)) +bstr_3 = b'\u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440' +print(bstr_3.decode("utf-16"), type(bstr_3)) diff --git a/hw_Lesson_01/2.py b/hw_Lesson_01/2.py new file mode 100644 index 0000000..09ccd31 --- /dev/null +++ b/hw_Lesson_01/2.py @@ -0,0 +1,7 @@ +bstr_1 = b'class' +bstr_2 = b'function' +bstr_3 = b'method' + +print('тип =',type(bstr_1),'содержимое =', bstr_1, "длина = ", len(bstr_1)) +print('тип =',type(bstr_2),'содержимое =', bstr_2, "длина = ", len(bstr_2)) +print('тип =',type(bstr_3),'содержимое =', bstr_3, "длина = ", len(bstr_3)) \ No newline at end of file diff --git a/hw_Lesson_01/3.py b/hw_Lesson_01/3.py new file mode 100644 index 0000000..d606ab6 --- /dev/null +++ b/hw_Lesson_01/3.py @@ -0,0 +1,4 @@ +bstr_1 = b"attribute" +# bstr_2 = b"класс" - SyntaxError: bytes can only contain ASCII literal characters. +# bstr_3 = b"функция" - SyntaxError: bytes can only contain ASCII literal characters. +bstr_4 = b"type" \ No newline at end of file diff --git a/hw_Lesson_01/4.py b/hw_Lesson_01/4.py new file mode 100644 index 0000000..872f44a --- /dev/null +++ b/hw_Lesson_01/4.py @@ -0,0 +1,14 @@ +str_1 = "разработка" +str_2 = "администрирование" +str_3 = "protocol" +str_4 = "standard" + +bstr_1 = str_1.encode() +bstr_2 = str_2.encode() +bstr_3 = str_3.encode() +bstr_4 = str_4.encode() + +print("encode =", bstr_1, "decode =", bstr_1.decode()) +print("encode =", bstr_2, "decode =", bstr_2.decode()) +print("encode =", bstr_3, "decode =", bstr_3.decode()) +print("encode =", bstr_4, "decode =", bstr_4.decode()) \ No newline at end of file diff --git a/hw_Lesson_01/5.py b/hw_Lesson_01/5.py new file mode 100644 index 0000000..a0a3941 --- /dev/null +++ b/hw_Lesson_01/5.py @@ -0,0 +1,17 @@ +import subprocess + +args = ['ping', 'yandex.ru'] + +subproc_ping = subprocess.Popen(args, stdout=subprocess.PIPE) + +for line in subproc_ping.stdout: + line = line.decode('cp866').encode('utf-8') + print(line.decode('utf-8'), end="") + +args = ['ping', 'youtube.com'] + +subproc_ping = subprocess.Popen(args, stdout=subprocess.PIPE) + +for line in subproc_ping.stdout: + line = line.decode('cp866').encode('utf-8') + print(line.decode('utf-8'), end="") diff --git a/hw_Lesson_01/6.py b/hw_Lesson_01/6.py new file mode 100644 index 0000000..9c91e12 --- /dev/null +++ b/hw_Lesson_01/6.py @@ -0,0 +1,17 @@ +import locale + +test_file = open("test_file.txt", "w") + +test_file.write("сетевое программирование\n") +test_file.write("сокет\n") +test_file.write("декоратор\n") +print(test_file) +test_file.close() + +def_coding = locale.getpreferredencoding() +print("кодировка файлов по умолчанию =", def_coding) + +print("Содержимое файла в Unicode:") +with open("test_file.txt", encoding="utf-16le") as f_n: + for el_str in f_n: + print(el_str, end='')