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

Резултати

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

Пребарај: #jet

当前筛选 #jet清除筛选
Universe Mysteries 🪐

@cosmomyst · Post #49 · 31.07.2025 г., 00:11

🪐 The massive elliptical galaxy Messier 87 in the Virgo Cluster possesses a jet of energetic plasma that extends for nearly 5,000 light-years from its supermassive black hole. This powerful jet glows fiercely in visible and X-ray light, fueled by material swirling toward the event horizon and launched at nearly the speed of light into intergalactic space. ✨ #M87⚡#blackhole⚡#jet⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space 👉subscribe Universe Mysteries

TOP Signals Spot

@cryptocurreniesbtc · Post #23033 · 09.08.2024 г., 16:28

Hello everyone, 48 hours left until our next free for all pump on MEXC!! The target this time will be 50X-100X gains possibly even more. B Bulls took a stand at the $50k support sparking an immediate and powerful rebound. The market now roars with bullish energy, and momentum is very strong indicating alts monster rally ahead so We can guarantee that this upcoming mega pump will have amazing results like our previous pumps: #YOLO (3200%) #VTS (3500%) #FRTN (6500%) #JET (+10600%) We are pumping on MEXC because MEXC is the best place to profit from small cap gems. There are a lot of trading pairs listed which allow us a breadth of options. Many retail, algo, and daily active traders use MEXC and will add additional volume to our signals and we believe that with our massive buying power we will be able to reach 50X-100X easily possibly even more as there is very little hidden sell pressure in the orderbooks. This event will be the biggest one that we have done in the history of our group and will top our previous ones in terms of % gain. we’re ready to see our biggest volume in history, Be prepared for a massive 50X-100X pump signal on MEXC this Sunday.

Mexc Crypto Signals Pumps Trading Kucoin

@mexc_signals_pumps_trading · Post #1267 · 09.08.2024 г., 17:19

Hello everyone, 47 hours left until our next free for all pump on MEXC!! The target this time will be 50X-100X gains possibly even more. Bulls took a stand at the $50k support sparking an immediate and powerful rebound. The market now roars with bullish energy, and momentum is very strong indicating alts monster rally ahead so We can guarantee that this upcoming mega pump will have amazing results like our previous pumps: #YOLO (3200%) #VTS (3500%) #FRTN (6500%) #JET (+10600%) We are pumping on MEXC because MEXC is the best place to profit from small cap gems. There are a lot of trading pairs listed which allow us a breadth of options. Many retail, algo, and daily active traders use MEXC and will add additional volume to our signals and we believe that with our massive buying power we will be able to reach 50X-100X easily possibly even more as there is very little hidden sell pressure in the orderbooks. This event will be the biggest one that we have done in the history of our group and will top our previous ones in terms of % gain. we’re ready to see our biggest volume in history, Be prepared for a massive 50X-100X pump signal on MEXC this Sunday.