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

Резултати

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

Пребарај: #gaza

当前筛选 #gaza清除筛选
RT en français

@RTenfrancais · Post #80793 · 04.05.2026 г., 10:20

🖼Gaza : soutien pictural ▪️Dans la bande de #Gaza, des artistes ont réalisé des fresques murales pour exprimer leur soutien à la flottille internationale Global Sumud. Crédit vidéo : Agence Anadolu RT en français • Osez questionner !

Hashtags

RT en français

@RTenfrancais · Post #80722 · 03.05.2026 г., 11:00

⏺À #Gaza, des mariés ont opté pour un moyen de transport inédit : une pelleteuse Le couple a traversé les rues, malgré les décombres témoignant de la destruction générale dont elles ont été le théâtre. Source : réseaux sociaux RT en français • Osez questionner !

Hashtags

🎥 Lа Prимиcя

@la_primicia · Post #71318 · 23.04.2026 г., 01:02

🫦 Algunas personas podrían encontrar perturbadoras las imágenes y videos compartidos. Se recomienda discreción. ⚠️🤔🏴‍☠️⚔️🇵🇸 Imágenes de la horrible masacre perpetrada por las fuerzas de ocupación contra un grupo de ciudadanos en el barrio de Beit Lahia, al norte de #Gaza.

Hashtags

Resistance News Network Backup

@RNN_Backup · Post #64825 · 25.10.2024 г., 14:45

🚨 The IOF carried out a new massacre, destroying an entire residential block above the heads of citizens on Tal Al-Zaatar in Jabalia, northern #Gaza Strip. Two martyrs have been recovered so far and there are a large amount of wounded. Artillery shelling continues on various parts of Jabalia, and several martyrs have ascended there as a result of residential homes being targeted. 4 martyrs and 5 injuries were reported as a result of the IOF targeting of a gathering of citizens on Al-Nasr Street west of Gaza City. Further, internet and communications have been cut off in the northern Gaza Strip as a result of the IOF aggression, as the siege enters its third week.

Hashtags

Resistance News Network Backup

@RNN_Backup · Post #64785 · 25.10.2024 г., 14:20

🚨🟢 BREAKING - Hamas leader Khalil Al-Hayya announces the martyrdom of the great leader, President of the Hamas Political Bureau, the hero of Al-Aqsa Flood, Yahya Sinwar, who sought martyrdom and attained it after clashing with a zionist force alongside other fighters in the #Gaza Strip. Further coverage of the Al-Hayya’s statement will be provided. Glory to the martyrs.

Hashtags

Resistance News Network Backup

@RNN_Backup · Post #64735 · 25.10.2024 г., 13:39

Ahmed Al-Telbani, Director of the Central Station in the Medical Services’ Emergency and Ambulance Department, ascended to martyrdom along with his family members in the IOF air strike of their home in Maghazi camp, central #Gaza Strip. Glory to the martyrs.

Hashtags

Resistance News Network Backup

@RNN_Backup · Post #64733 · 25.10.2024 г., 13:37

🔻 The IOF admits to the death of 5 IOF soldiers, including two officers, during a battle with the resistance in southern Lebanon. In the same incident, three Golani Brigade soldiers (including an officer) were seriously wounded. In total, the IOF admitted to the critical wounding of 8 zionist soldiers in three battles in southern Lebanon. They also admitted to the serious wounding of a soldier during a battle in the southern #Gaza Strip yesterday.

Hashtags

Resistance News Network Backup

@RNN_Backup · Post #64705 · 25.10.2024 г., 13:11

🚨 10 martyrs have been recovered by Civil Defense crews following the IOF bombing the Al-Telbani family home in Maghazi camp in the central #Gaza Strip. 60 martyrs have ascended in the Gaza Strip today, with at least 25 of them in Jabalia camp.

Hashtags

Resistance News Network Backup

@RNN_Backup · Post #64698 · 25.10.2024 г., 13:09

On October 17th, 2023, in a cowardly assassination, commander Ayman Nofal ascended after US-funded IOF warplanes targeted him in Bureij camp in central #Gaza. Beloved by allfactions, the commanding martyr was an Al-Qassam Brigades leader who created the foundations of the united Joint Operations Room of Palestinian Resistance Factions, a room in which the spectrum of Palestinian and Arab resistance coordinate. Just weeks ago, Ayman's nephew was martyred at the Gaza border protests. Ayman embodied the spirit of the Joint Room which he led in his words and deeds, recognizing, like martyred leaders before him, "Either we rise together, or they will kill us individually." Here, Ayman speaks in 2021 at the Joint Operation's Room annual training for all factions. Without a doubt, Ayman was one of the engineers of the long-planned Al-Aqsa Flood for the sake of our prisoners and Al-Aqsa, evident in the words of this speech: GiladShalit was just practice. Learning from the lessons of previous operations and honoring the blood of the martyrs, we march forth towards liberation, never forgetting those who paved the path. Glory to our martyrs! Glory to our resistance! Liberation nears with their guiding illumination.

Hashtags

Resistance News Network Backup

@RNN_Backup · Post #64674 · 25.10.2024 г., 12:52

🚨 22 martyrs have ascended in the horrific massacre at the Abu Hussein School in Jabalia camp, northern #Gaza Strip, and dozens are wounded. Most of the martyrs are children and women, after the IOF bombed the school housing a large number of displaced people. Tanks began firing shells at the school after advancing from west of Jabalia. The hospitals in the north are unable to deal with the large number of injuries and martyrs. The IOF also bombed the Khalifa School in the northern #Gaza Strip, resulting in a large fire and one martyr. In a series of strikes, at least 11 martyrs ascended in Gaza City. The siege of Jabalia camp and the north continues for the 13th day without any aid reaching it.

Hashtags

123•••5•••10•••15•••20•••25•••30•••35•••40•••45•••5051
ПретходнаСтраница 1 од 51Следна