TGTGInsighttelegram intelligenceLIVE / telegram public index
← Python Заметки

TGINSIGHT SIMILAR POSTS

Најди сличен содржај

Изворен канал @pythonotes · Post #242 · 7 мај

Теперь запакуем строку. В этом случае следует передавать тип данных bytes. >>> struct.pack('=s', b'a') b'a' Для записи слова следует указывать количество символов. >>> struct.pack('=5s', b'hello') b'hello' Кстати, запакованный вид соответствует исходному тексту. Всё верно, символ есть в таблице ASCII, то есть его код попадает в диапазон 0-127, он может быть записан одним байтом и имеет визуальное представление. А вот что будет если добавить символ вне ASCII >>> struct.pack(f'=s', b'ё') SyntaxError: bytes can only contain ASCII literal characters. Ошибка возникла еще на этапе создания объекта bytes, который не может содержать такой символ. Поэтому надо кодировать эти байты из строки. >>> enc = 'ёжик'.encode('utf-8') >>> struct.pack(f'={len(enc)}s', enc) b'\xd1\x91\xd0\xb6\xd0\xb8\xd0\xba' Заметьте, длина такой строки в байтах отличается от исходной длины, так как символы вне ASCII записываются двумя байтами и более. Поэтому здесь формат создаём на лету, используя получившуюся длину как каунтер токена. #libs#basic

Hashtags

Резултати

Пронајдени 2 слични објави

Пребарај: #anger

当前筛选 #anger清除筛选
Self-Immolation

@SelfImmolation · Post #908 · 18.07.2022 г., 17:31

How to react if someone is angry with you? One time Brahmin Akkosaka got angry at Buddha, because a man from his clan had become a Bhikkhu. Akkosaka was yelling and insulting the Buddha. Buddha: “What do you think, Akkosaka? Do your friends, relatives, and guests sometimes come to visit you?” Akkosaka: "Sometimes they do, Master Gotama.” Buddha: "Do you then serve them with a variety of food and drinks?” Akkosaka: "Sometimes I do.” Buddha: “But if they don’t accept it, who do those food and drinks belong to?” Akkosaka: “In that case Master Gotama, they still belong to me.” Buddha: “In the same way, Akkosaka, when you abuse, harass, and attack me, who does not abuse, harass, and attack, I don’t accept your insults. They still belong to you, Akkosaka, they still belong to you!" - SN 7.2 Akkosaka Sutta#anger#Buddha