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

Резултати

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

Пребарај: #lebanon

当前筛选 #lebanon清除筛选
bintjbeil.org - موقع بنت جبيل

@bintjbeilnews · Post #171348 · 10.04.2026 г., 13:03

🚨الخارجية الفرنسية: الوزيران الفرنسي والباكستاني أكدا أهمية إدراج لبنان ضمن بنود وقف إطلاق النار لضمان استمراره French Foreign Ministry: The French and Pakistani ministers emphasized the importance of including #Lebanon within the ceasefire terms to ensure its sustainability. ــــــــــــــ 📲 قناة موقع بنت جبيل على واتساب https://whatsapp.com/channel/0029VaG3H3R8fewmfDqRKX0Q

Hashtags

AlHaq News | Iran-US War Updates

@AlhaqNews · Post #33508 · 09.04.2026 г., 17:28

🇵🇰🇮🇷🇱🇧🔻Pakistan’s Minister of Defense, H.E KHAWAJA MUHAMMAD ASIF: Israel is an evil and a curse on humanity. While peace talks are underway, it commits genocide in #Lebanon. @AlHaqNews

Hashtags

Islamic World News

@iswnews_en · Post #18586 · 13.04.2026 г., 14:41

🇱🇧🇱🇧Hussein Wahib Yassin (Haj Abu Mohammad Habib), a senior commander of Hezbollah, was martyred as a result of an airstrike by the Zionist regime’s army on southern Lebanon. 🟡 Martyr Yassin was from the town of Majdel Selm in southern Lebanon and was an experienced field commander of Hezbollah. His record includes participation in the 33‑day war, the Battle of Al‑Aqsa Storm on the southern Lebanon front, the Syrian war, and accompanying the martyred commanders Haj Qasem Soleimani and Haj Emad Mughniyeh. 🟡 The exact time and place of this mujahid commander’s martyrdom are not specified. #Lebanon

Hashtags

Islamic World News

@iswnews_en · Post #18525 · 09.04.2026 г., 23:29

🇱🇧 According to a new report from the Lebanese Ministry of Health, the death toll from yesterday’s Israeli attacks on Lebanon has now reached 303 martyrs, with over 1,150 wounded. ✍️ Unfortunately, the casualty count continues to rise. Hezbollah, without any support from Lebanon’s incompetent government, is defending the country’s soil and its people. #Lebanon

Hashtags

POPULAR FRONT

@popularxfront · Post #5991 · 23.04.2026 г., 09:21

🇱🇧#Lebanon: The statue of Jesus Christ which was destroyed by an IDF soldier was replaced yesterday by a new one which was donated by Italian UNIFIL troops.

Hashtags

POPULAR FRONT

@popularxfront · Post #5853 · 10.04.2026 г., 15:02

🇱🇧#Lebanon: Lebanon’s prime minister has reportedly ordered the Lebanese Army to deploy across Beirut to ensure that only official armed forces have access to weapons, restricting possession exclusively to state security institutions. The government has also decided to file an urgent complaint with the United Nations Security Council in response to Israel’s indiscriminate attacks on civilian infrastructure in Lebanon. At the start of the session, the PM stated that Lebanon is "tired of mere statements of condemnation", expressing frustration that the country was not included in the ceasefire announced between the US and Iran. (via MTV news)

Hashtags

POPULAR FRONT

@popularxfront · Post #5461 · 16.03.2026 г., 12:16

🇱🇧#Lebanon: The pro-Iranian hacktivist group "Fatemiyoun Electronic Team" (FET) targeted the website of MTV Lebanon overnight, issuing threats against the channel and causing a temporary outage. The group carries out digital attacks on behalf of the Iraqi militia "Kataib Hezbollah" (also known as Hezbollah Brigades), which is part of the Popular Mobilization Forces (PMF). (via @LebOSINT on X)

Hashtags

123•••10•••20•••30•••3637
ПретходнаСтраница 1 од 37Следна