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

Резултати

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

Пребарај: #kerch

当前筛选 #kerch清除筛选
Rybar DE

@rybardeu · Post #3152 · 05.04.2026 г., 15:37

📝Auch im Asowschen Meer📝 leidet die Schifffahrt Eine Folge des Anwachstums ukrainischer Anschläge auf die russische Exportinfrastruktur hat die Schifffahrt im Asowschen Meer erreicht. Dort kommen Frachtschiffe unter Beschuss durch ukrainische Drohnen. 🔻Was ist passiert? ➡️Gestern kam Taganrog unter Beschuss, einschließlich des Hafens, wo ein Trockenfrachter beschädigt wurde. ➡️Heute gab es einen weiteren Anschlag. Ein Trockenfrachter vom Typ Wolga-Ostsee, der Weizen transportierte, sank, und die Besatzung erreichte die Region Cherson. 🖍Die AFU greift gezielt die Haupteinnahmequelle des russischen Haushalts an - Exporte. 🚩Anschläge beschädigen Infrastruktur, die repariert werden muss, und Operationen müssen eingestellt werden. 🏳️Jeder Anschlag auf Schiffe beraubt Russland seltener Handelssschiffe. Frachtkosten werden steigen. ❗️Der Feind wird nicht aufhören, bis ausreichende Gegenmaßnahmen umgesetzt werden. Der Ausweg ist, sogenannte ukrainische Schiffe auf dem Meer anzugreifen. Die Schifffahrt in der Region Odesa floriert trotz allem. #Krim#Kerch#Russland#Ukraine ✈️RU | ✈️EN | ✉️MAX ✉️VK | ✉️RuTube | ✉️

Russian MFA 🇷🇺

@MFARUSSIA · Post #29157 · 11.04.2026 г., 05:59

#Victory81 🌟 On April 11, 1944, during the Crimean offensive operation, Soviet forces liberated #Kerch from Nazi occupiers. Kerch was among the first cities to endure assaults from Hitler’s army at the beginning of the Great Patriotic War. It found itself repeatedly on the front line, with the battlefront cutting through its very streets. Moreover, the city fell under enemy occupation twice. Initially captured in November 1941, Kerch was liberated barely a month later in December, following the Kerch–Feodosia amphibious landing operation. In the spring of 1942, the enemy amassed significant forces on the Kerch Peninsula and launched a renewed offensive. Despite the valiant resistance by the defenders, the city once again came under fascist control, remaining occupied for 320 days. During that period, approximately 15,000 civilians lost their lives, and over 14,000 individuals were forcibly deported to Germany for slave labour. 🕯#NoStatuteOfLimitations: The Bagerovo Ditch near Kerch gained tragic notoriety – a site of mass executions. Towards the end of 1941, around 7,000 people were executed and tortured there, including 245 schoolchildren. The Germans surreptitiously removed the children from the city and poisoned them with potassium cyanide. The Nazi occupiers obliterated every factory, burned bridges and vessels, destroyed parks, and decimated the city’s infrastructure. Kerch was almost completely erased from the map. One of the war’s most heroic episodes was the defence of the Adzhimushkay quarry. Thousands of civilians – elderly people, women, and children – sought refuge within the underground passages. The enemy attempted to exterminate them by sealing the entrances and using explosives and toxic substances. Nearly all the defenders perished, yet they continued to resist to the very end, rendering the quarry a symbol of unyielding courage and resilience. ⚔️ On the night of November 1, 1943, the Kerch-Eltigen amphibious landing operation commenced. Soviet forces established a bridgehead north of the city, marking a crucial phase in liberating the Kerch Strait and the entire Crimea. In the spring of 1944, this success was solidified during the Crimean offensive operation, culminating in the expulsion of the occupiers from the peninsula. One of Kerch’s principal symbols became the Obelisk of Glory on Mount Mithridat, unveiled on August 8, 1944 – the first monument in the USSR dedicated to the Great Patriotic War. 🎖 For the defence and liberation of the city, 153 individuals were awarded the title of Hero of the Soviet Union, and 21 military units and formations received the honorary designation “Kerch.” On September 14, 1973, Kerch was awarded the title #HeroCity.

Russian Embassy in Albania

@rusembalb · Post #7964 · 11.04.2026 г., 15:59

#Victory81 🌟 On April 11, 1944, during the Crimean offensive operation, Soviet forces liberated #Kerch from Nazi occupiers. Kerch was among the first cities to endure assaults from Hitler’s army at the beginning of the Great Patriotic War. It found itself repeatedly on the front line, with the battlefront cutting through its very streets. Moreover, the city fell under enemy occupation twice. Initially captured in November 1941, Kerch was liberated barely a month later in December, following the Kerch–Feodosia amphibious landing operation. In the spring of 1942, the enemy amassed significant forces on the Kerch Peninsula and launched a renewed offensive. Despite the valiant resistance by the defenders, the city once again came under fascist control, remaining occupied for 320 days. During that period, approximately 15,000 civilians lost their lives, and over 14,000 individuals were forcibly deported to Germany for slave labour. 🕯#NoStatuteOfLimitations: The Bagerovo Ditch near Kerch gained tragic notoriety – a site of mass executions. Towards the end of 1941, around 7,000 people were executed and tortured there, including 245 schoolchildren. The Germans surreptitiously removed the children from the city and poisoned them with potassium cyanide. The Nazi occupiers obliterated every factory, burned bridges and vessels, destroyed parks, and decimated the city’s infrastructure. Kerch was almost completely erased from the map. One of the war’s most heroic episodes was the defence of the Adzhimushkay quarry. Thousands of civilians – elderly people, women, and children – sought refuge within the underground passages. The enemy attempted to exterminate them by sealing the entrances and using explosives and toxic substances. Nearly all the defenders perished, yet they continued to resist to the very end, rendering the quarry a symbol of unyielding courage and resilience. ⚔️ On the night of November 1, 1943, the Kerch-Eltigen amphibious landing operation commenced. Soviet forces established a bridgehead north of the city, marking a crucial phase in liberating the Kerch Strait and the entire Crimea. In the spring of 1944, this success was solidified during the Crimean offensive operation, culminating in the expulsion of the occupiers from the peninsula. One of Kerch’s principal symbols became the Obelisk of Glory on Mount Mithridat, unveiled on August 8, 1944 – the first monument in the USSR dedicated to the Great Patriotic War. 🎖 For the defence and liberation of the city, 153 individuals were awarded the title of Hero of the Soviet Union, and 21 military units and formations received the honorary designation “Kerch.” On September 14, 1973, Kerch was awarded the title #HeroCity.