Можно ли в Python создавать бинарные файлы? Конечно можно.
Для этого в Python есть следующие инструменты:
▫️ тип данных bytes и bytearray
▫️ открытие файла в режиме wb (write binary) или rb (read binary)
▫️ модуль struct
Про модуль struct поговорим в первую очередь.
Файл в формате JSON или Yaml внутри себя содержит разметку данных. Всегда можно определить где список начался а где закончился. Где записана строка а где словарь. То есть формат записи данных содержит в себе элементы разметки данных.
В binary-файле данные не имеют визуальной разметки. Это просто байты, записанные один за другим. Правила записи и чтения находятся вне файла.
Модуль struct как раз и помогает с организацией данных в таком файле с помощью определения форматов записи для разных частей файла.
Модуль struct преобразует Python-объекты в массив байт, готовый к записи в файл и имеющий определённый вид.
Для этого всегда следует указывать формат преобразования (или, как оно здесь называется - запаковки).
Формат нужен для того, чтобы выделить достаточное количество байт для записи конкретного типа объекта. В последствии с помощью того же формата будет производиться чтение.
При этом следует помнить что мы говорим о типах языка С а не Python.
Именно формат определяет, что записано в конкретном месте файла, число, строка или что-то еще.
Вот какие токены формата у нас есть.
Помимо этого, первым символом можно указать порядок байтов. На разных системах одни и те же типы данных могут записываться по-разному, поэтому желательно указать конкретный способ из доступных. Если этого не сделать, то используется символ '@', то есть нативный для текущей системы.
В строке формата мы пишем в каком порядке и какие типы собираемся преобразовать в байты.
Запакуем в байты простое число, токен "i".
>>> import struct
>>> struct.pack('=i', 10)
b'\n\x00\x00\x00'
Теперь несколько float, при этом нужно передавать элементы не массивом а последовательностью аргументов.
>>> struct.pack('=fff', 1.0, 2.5, 4.1)
b'\x00\x00\x80?\x00\x00 @33\x83@'
Вместо нескольких токенов можно просто указать нужное количество элементов перед одним токеном, результат будет тот же.
>>> struct.pack('=3f', 1.0, 2.5, 4.1)
b'\x00\x00\x80?\x00\x00 @33\x83@'
Теперь запакуем разные типы
>>> data = struct.pack('=fiQ', 1.0, 4, 100500)
я запаковал типы float, int и unsigned long long (очень большой int, на 8 байт)
b'\x00\x00\x80?\x04\x00\x00...'
Распаковка происходит аналогично, но нужно указать тот же формат, который использовался при запаковке. Результат возвращается всегда в виде кортежа.
>>> struct.unpack('=fiQ', data)
(1.0, 4, 100500)
Как видите, ничего страшного!
#lib#basic
#Security vacuum fears grow amid reports of #ENDF withdrawals, alleged redeployment toward #Tigray Region
Withdrawal or reduced presence of federal forces in recent days is raising concerns among local communities. Residents in different parts of the country spoke to Addis Standard on their concern following federal forces evacuating their village while fueling speculation that troops are being redeployed northward amid rising tensions involving Tigray.
Residents in Dirashe district, Gardulla Zone, South Ethiopia Region, and Anfilo districts in Kellem Wollega Zone, Oromia Region, told Addis Standard that Ethiopian National Defense Forces (ENDF) have been vacating certain areas, creating security gaps and fueling local tensions. An AFP report confirmed similar reports of troop movements and heightened military tension near the Tigray border.
https://addisstandard.com/?p=55250
News: #Ethiopia, #Belarus sign military MoU ahead of Air Force’s 90th anniversary
Ethiopia and Belarus have signed a bilateral memorandum of understanding (MoU) aimed at strengthening military cooperation between the two countries, the Ethiopian National Defense Forces (#ENDF) said.
In a statement issued on 22 January 2026, the ENDF said the agreement was signed by Ethiopia’s Minister of Defense, Engineer Aisha Mohammed, and Pantus Dmitry Aleksandrovich, Minister of State Authority for Military Industry of the Republic of Belarus.
According to the statement, Aisha described the MoU as a significant step toward advancing Ethiopia’s military technology and industrial capacity, particularly as the country seeks greater self-sufficiency in defense production.
She also recalled previous agreements reached between the leaders of Ethiopia and Belarus, noting that those understandings provide the foundation for implementing the current strategic cooperation...
Read more: https://addisstandard.com/?p=54710
#ENDF Airborne School graduates combat paratroopers trained for #special_missions
Addis Abeba— The Ethiopian National Defense Force (ENDF) said its Airborne School, under the Special Operations Command Training Center, has today graduated combat paratroopers trained to carry out special missions.
Lieutenant General Shuma Abdeta, Commander of the Special Operations Command, attended the graduation ceremony and pinned “chest wings” on the graduates, according to a statement from ENDF.
Addressing the trainees, Lt. Gen. Shuma said the airborne force “is a cradle of great leaders and heroes,” describing it as a unit that “makes the country proud by concluding formidable and complex missions with victory.”
He added that joining the airborne force requires “exceptional bravery,” noting that a paratrooper must be “a determined hero, invincible to any earthly challenge, and capable of overcoming all obstacles to achieve success.”
https://www.facebook.com/share/1KTQkTwcNF/
News: #Tigray Interim Administration dismisses claims of #ENDF deployment, relocation to Northern Command camps
The Tigray Interim Administration has dismissed as “completely false” reports circulating in recent days alleging that the federal government ordered the #Ethiopian National Defense Forces (ENDF) to enter Tigray and that the regional administration had agreed to the relocation of federal troops to former Northern Command camps.
In a brief statement issued today, the Interim Administration described the claims as “misinformation and disinformation” intended to mislead the public and create unnecessary tension.
“There are rumors in recent days that the federal government has ordered the Ethiopian Defense Forces to enter Tigray, and the Tigray Interim Administration has agreed for the forces to settle in the former camps of #Northern Command,” the statement said.
“The source and the goal of this strategy of spreading such misinformation and....
Read more: https://addisstandard.com/?p=55289
News: Former minister #Gedu says #Eritrean, #Ethiopian forces operated “as a single force” until Pretoria ceasefire, disputes PM Abiy’s account of Asmara’s role in Tigray war
Former Minister of Foreign Affairs Gedu Andargachew has disputed Prime Minister Abiy Ahmed’s recent parliamentary account of Ethiopia’s wartime engagement with Eritrea, saying Eritrean forces fought alongside the Ethiopian National Defense Forces (#ENDF) “effectively as a single force” until the Pretoria ceasefire halted joint operations.
He said he proposed raising the withdrawal of Eritrean forces from Tigray during the visit but was instructed not to do so. According to Gedu, no message concerning the suffering of civilians in Tigray was delivered in Asmara.
In a letter dated 5 February 2026 and sent to Addis Standard, Gedu rejected Abiy’s claim that he served as the Prime Minister’s envoy to Eritrea after the outbreak of the war in Tigray to convey concerns over crimes ....
Read more: https://addisstandard.com/?p=55048
News: #US Assistant Secretary Christopher Landau, AFRICOM commander arrive in #Ethiopia, visit Air Force aviation expo
U.S. Assistant Secretary of State Christopher Landau arrived in Ethiopia today as part of a regional tour that includes #Egypt, Ethiopia, #Kenya, and #Djibouti, scheduled to run from 24 January to 1 February.
The Commander of the U.S. Africa Command (#AFRICOM), General Dagvin Anderson, is also in Ethiopia as part of the visit.
Today, Landau and General Anderson visited the International Aviation Expo organized by the Ethiopian Air Force, according to the Ethiopian National Defense Force (#ENDF). Field Marshal Birhanu Jula, Chief of General Staff of the Ethiopian National Defense Force, also took part in the visit.
The expo showcased aircraft, defense technologies, and related products from the Ethiopian Air Force, the Defense Engineering Industry Group,..
https://www.facebook.com/AddisstandardEng/posts/pfbid021qedgKswfSFzdABsQXmFSvjuiRtWQedXpLYXJysCdk1MBnWvdx4JZJTmEng9jPGRl