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

TGINSIGHT SIMILAR POSTS

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

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

Можно ли в 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

Hashtags

Резултати

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

Пребарај: #mozambique

当前筛选 #mozambique清除筛选
POPULAR FRONT

@popularxfront · Post #4895 · 04.02.2026 г., 17:38

🇲🇿#Mozambique: IS-Mozambique (ISMP, Islamic State in Mozambique) released a video today claiming responsibility for an attack last Sunday targeting Mozambican military bases in the Katuba and Namapo areas of Cabo Delgado in the northern part of the country. As a result of the attacks, it is reported that nine Mozambican soldiers were killed. The militants also posted footage showing weapon caches and equipment they captured from the bases. (via @BrantPhilip_ on X)

Hashtags

Russian MFA 🇷🇺

@MFARUSSIA · Post #28776 · 19.03.2026 г., 12:59

⚡️Russia's EMERCOM: On March 19, a special flight of Russia's EMERCOM delivered humanitarian aid to the Republic of #Mozambique. By decision of Russia's President Vladimir Putin, following instructions from the Government of Russia and on the orders of EMERCOM Head Alexander Kurenkov, around 29 tonnes of humanitarian cargo were transported from Moscow. 🛬 An Il-76 aircraft delivered food, essential supplies, as well as tents and blankets for flood-affected communities in the African republic. #RussiaHelps

ጠቅላይ ሚኒስትር ዐቢይ አሕመድ (ዶ/ር) ለሞዛምቢኩ ፕሬዝደንት ዳንኤል ፍራንሲስኮ ቻፖ ደማቅ አቀባበል አደረጉ ************** ጠቅላይ ሚኒስትር ዐቢይ አሕመድ (ዶ/ር) በኢትዮጵያ ይፋዊ የሥራ ጉብኝት ለማድረግ የመጡትን የሞዛምቢክ ፕሬዝደንት ዳንኤል ፍራንሲስኮ ቻፖን በቦሌ ዓለም አቀፍ አውሮፕላን ማረፊያ በመገኘት በክብር ተቀብለዋል። የፕሬዝደንቱ ጉብኝት በሁለቱ ሀገራት መካከል ያለውን ዲፕሎማሲያዊ እና ኢኮኖሚያዊ ግንኙነት ወደ አዲስ ምዕራፍ ያሸጋግራል ተብሎ ይጠበቃል። ጉብኝቱ የሁለቱን ሀገራት ታሪካዊ ግንኙነት ወደ ላቀ ደረጃ የሚያሸጋግር ሲሆን፣ ኢትዮጵያ ለእውነተኛ አፍሪካዊ አጋርነት ያላትን የማይናወጥ ቁርጠኝነት የሚያረጋግጥ መሆኑን የጠቅላይ ሚኒስትር ጽ/ቤት አስታውቋል። #EBC#Ethiopia#PMOEthiopia#Mozambique#diplomacy

Reuters: World

@reutersworldchannel · Post #149314 · 13.10.2021 г., 16:57

The struggle for water in Mozambique's unstable north Aid agencies warn that a shortage of safe water, poor sanitation and inadequate medical services are a looming threat for the communities in Mozambique's Cabo Delgado province #News#Reuters#Mozambique#RedCross Subscribe: http://smarturl.it/reuterssubscribe Reuters brings you the latest business, finance and breaking news video from around the globe. Our reputation for accuracy and impartiality is unparalleled. Get the latest news on: http://reuters.com/ Follow Reuters on Facebook: https://www.facebook.com/Reuters Follow Reuters on Twitter: https://twitter.com/Reuters Follow Reuters on Instagram: https://www.instagram.com/reuters/?hl=en ➖@reutersworldchannel➖

Russian MFA 🇷🇺

@MFARUSSIA · Post #27890 · 26.12.2025 г., 09:35

#RussiaHelps 💬Maria Zakharova: OnDecember 17 inMaputo (#Mozambique) and December 18 inLusaka (#Zambia), official ceremonies marking the delivery of Russian food assistance were held, attended by the Russian Ambassadors to these countries. 🇲🇿 Mozambique received 70 tonnes of vitamin-fortified sunflower oil for those in need. 🇿🇲 Zambia received a similar shipment of 93 tonnes, as well as 648 tonnes of yellow split peas. These humanitarian deliveries were carried out through the UN World Food Programme, funded by Russia’s voluntary contribution for African countries, which amounts to USD 10 million annually. Humanitarian assistance is an integral part of Russia’s support for its partners on the African continent, primarily aimed at helping the most vulnerable groups. 🇷🇺 Russia will continue to contribute to addressing Africa’s socio-economic challenges, using both bilateral assistance mechanisms and the potential of relevant international organizations. (Excerpt from Russian MFA Spokeswoman Maria Zakharova's weekly briefing on December 26)

AREA

@area_eng · Post #120 · 24.07.2025 г., 20:46

Russia and Mozambique may expand energy cooperation During a visit to Moscow, Mozambique Foreign Minister Maria Manuela dos Santos Lucas said that the country views Russia as a strategic partner in the development of the oil and gas sector. For Mozambique, which has the sixth largest natural gas reserves in Africa (about 100 trillion cubic feet), partnership with Russia is indeed of strategic value. Russian companies offer not only investments, but also unique competencies in the development of offshore fields, construction of gas transportation infrastructure and training of qualified personnel. Today, about 40% of Mozambican students in the Russian Federation are studying in specialties needed in the oil and gas sector. Despite Rosneft's withdrawal from the Mozambique LNG project in 2022, Russian companies remain interested in the region. In particular, Gazprom continues to explore the possibility of working on the Mozambican shelf. According to experts, there are several key vectors of cooperation between the parties. This could be the creation of an LNG cluster using Russian technologies, joint projects for gasification of Mozambique regions, as well as the development of educational programs for training personnel. #AREA#Africa#Russia#RussiaAfrica#energy#Mozambique