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

Резултати

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

Пребарај: #trade

当前筛选 #trade清除筛选
Indian Development News 🇮🇳

@developmentnewsindia · Post #44126 · 27.04.2026 г., 14:35

Indian Delegation To Visit Russia For Next Round Of India-EAEU FTA Talks In June 2026 #Trade 🚨India, Russia-Led EAEU Bloc Had Launched Talks For An FTA On 26th November 2025 🚨The EAEU Comprises Of Russia, Kazakhstan, Armenia, Belarus, And Kyrgyzstan; With An Observer Status To Cuba, Moldova, And Uzbekistan

Hashtags

Indian Development News 🇮🇳

@developmentnewsindia · Post #44121 · 27.04.2026 г., 09:15

𝐀 𝐦𝐚𝐬𝐬𝐢𝐯𝐞 𝐰𝐢𝐧 𝐟𝐨𝐫 𝐈𝐧𝐝𝐢𝐚’𝐬 𝐞𝐱𝐩𝐨𝐫𝐭𝐞𝐫𝐬 🇮🇳🤝🇳🇿. The India–New Zealand FTA signed today ensures 100% duty-free access across all tariff lines, eliminating earlier tariffs of up to 10% on textiles, leather, carpets, ceramics, and auto components, boosting competitiveness, cutting costs, and unlocking new markets. #Trade

Hashtags

Indian Development News 🇮🇳

@developmentnewsindia · Post #43413 · 09.04.2026 г., 16:33

Bangladesh to import 200 broad-gauge coaches from India by 2027 The project, financed by the European Investment Bank, is expected to see the coaches added to the Bangladesh Railway fleet between June 2026 and December 2027. #trade

Hashtags

𝐗 𝐀𝐋𝐏𝐇𝐀𝐒

@apksarena · Post #4342 · 19.02.2026 г., 19:57

I’ve been on @Vault777Casino for a while now and it’s honestly one of the most engaging virtual trading platforms I’ve used to #trade Fast predictions, leaderboards, rewards, and real strategy

Hashtags

TONlines – News

@tonlines · Post #7501 · 17.11.2025 г., 16:27

⚡️ Storm Trade: Update Completed and New Features Announced #TON#trade The Storm Trade update has been completed successfully. The platform now uses the Pyth price feed protocol, offering faster and more accurate price updates. This upgrade enhances UI interaction and sets the stage for the upcoming V3 launch on TON. Source: link @tonlines

Hashtags

Indian Development News 🇮🇳

@developmentnewsindia · Post #43850 · 20.04.2026 г., 12:01

🇮🇳🤝🇰🇷 Looking forward to PM Modi visiting South Korea says SK President Lee Jae Myung Indian Officials say an upgraded India-SK CEPA Agreement could be signed during the Visit. 2009 CEPA Agreement reduced Tariffs on 85% Indian Products to SK and 90% SK products to India #Geopolitics#Trade

Trump's Ear

@trumpsear_tg · Post #2107 · 05.02.2026 г., 13:59

Trump sees resumption of trade with Russia as a guarantee of ending the conflict - Foreign Policy In his policy of resolving the conflict in Ukraine, Donald Trump is betting to restore trade relations with Russia as the most important factor of peace. He argues that economic cooperation will benefit American investors and ensure stability in the region. The US administration also believes that trade agreements with Russia, such as energy sector deals, can serve as a guarantor of peace. #Trump#Russia#Trade 👂More on Trump's Ear ⚠️

TONlines – News

@tonlines · Post #7500 · 17.11.2025 г., 16:06

Portals Community: Season 2 Launches with Points Farming #Portals#trade Portals Community announces the return of Points Farming with the launch of Season 2, allowing users to earn points and cashback on every trade. Users can enhance their progress by completing tasks, with more earning opportunities to come. Stay tuned for another major update arriving tomorrow. Source: link @tonlines

123•••101112
ПретходнаСтраница 1 од 12Следна