Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions hw_Lesson_01/1.py
Original file line number Diff line number Diff line change
@@ -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))
7 changes: 7 additions & 0 deletions hw_Lesson_01/2.py
Original file line number Diff line number Diff line change
@@ -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))
4 changes: 4 additions & 0 deletions hw_Lesson_01/3.py
Original file line number Diff line number Diff line change
@@ -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"
14 changes: 14 additions & 0 deletions hw_Lesson_01/4.py
Original file line number Diff line number Diff line change
@@ -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())
17 changes: 17 additions & 0 deletions hw_Lesson_01/5.py
Original file line number Diff line number Diff line change
@@ -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="")
17 changes: 17 additions & 0 deletions hw_Lesson_01/6.py
Original file line number Diff line number Diff line change
@@ -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='')