Теперь запакуем строку.
В этом случае следует передавать тип данных 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
TON — LIVE: Telegram Rises in Popularity Rankings
#Telegram#apps
The channel TON — LIVE reports that Telegram has moved up one rank in the list of the most popular apps for 2025.
Source: link
@tonlines
⚡️Trending Apps: New Voting System in Telegram Apps Center
#Telegram#Apps
Trending Apps announces that users can now influence the ranking of Mini Apps through a new voting system in the Telegram Apps Center. Active participants will be rewarded with exclusive SBTs and Telegram Gifts.
Source: link
@tonlines
⚡️Trending Apps: Upcoming Feature in Apps Center
#Telegram#Apps
Trending Apps announced a new feature in the Apps Center, aiming to enhance user engagement by allowing users to influence developments directly. This innovative approach is set to launch within the next 30 days, with more details to be revealed gradually.
Source: link
@tonlines
A partir de hoy amigos, estaré entregando #apps, recursos, plataformas y tips para usar la tecnología a su favor y mejorar las condiciones de #empleo📄📈