Теперь запакуем строку.
В этом случае следует передавать тип данных 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
🇽🇰#Kosovo: Kosovo Police has found yet another cache of weapons, ammunition, and military gear yesterday, after searching the basement of a residential building on Vasilije Ostroški Street in North Mitrovica.
Officers recovered multiple assault rifles, hundreds of rounds of ammunition, magazines, a smoke grenade, body armor, and various pieces of military clothing and equipment. No arrests were made, and an investigation into illegal weapons possession is ongoing.
This comes as, over the past week, several abandoned weapons caches have been discovered in the north, including one containing hundreds of kilograms of explosives and a practice anti-tank mine. It remains unclear whether the stashes are linked to a specific paramilitary group or a criminal organization.
(📸 via @KosovoPolice on FB)
🇽🇰#Kosovo: Kosovo Police have uncovered weapons, ammunition, and explosives in abandoned houses in Zubin Potok, Zvečan, and the North Mitrovica area since the start of this week.
Just in North Mitrovica, authorities seized around 140 kg of explosives, which they say were produced in Serbia.
The latest seizure was yesterday in Mitrovicë Veri, where police, acting on information from citizens, found several illegal weapons, ammunition, and a VPMA-2 (a practice version of the PMA-2 anti-personnel mine).
(📸 via @Kosovo_police on X)
#Kosovo
L’Assemblea della Repubblica del Kosovo ha adottato un progetto di legge finalizzato alla regolamentazione giuridica del diritto alla riproduzione sessuale e della procreazione medicalmente assistita.
@OsservatorioEsteri
#Kosovo🇽🇰
#Parlamentari
🕖Ore 19:00.
Affluenza parziale: 44,29%
N.B.: nel computo mancano i seggi speciali, quelli allestiti all'estero e alcune sezioni allestite nel Paese, che non hanno ancora comunicato i dati.
@TuttoElezioni
#Kosovo#primario Huelga en la mina Trepca https://www.aa.com.tr/en/europe/kosovo-mine-workers-begin-hunger-strike-for-better-working-conditions/3032646
‼️A la chita callando, #España pasa a reconocer la independencia de #Kosovo. Un nuevo giro de 180º de Sánchez alinéandose con #EEUU que impulsa la #guerra
https://www.euractiv.com/section/enlargement-neighbourhood/news/kosovo-says-spain-recognises-its-passports/
#Kosovo#NATO
Il governo del Kosovo ha chiesto agli Stati Uniti una base permanente sul suo territorio ed ha chiesto di entrare nella NATO.
@UltimoraPolitics
#Kosovo
Il Presidente del Kosovo Hashim #Thaçi si è dimesso dopo che è stata confermata l'accusa di crimini di guerra e crimini contro l'umanità dalla Procura dell'Aia.
@NewsDalMondoo