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

Резултати

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

Пребарај: #hipo

当前筛选 #hipo清除筛选
TONlines – News

@tonlines · Post #7701 · 04.12.2025 г., 08:04

⚡️Hipo: Track Your hTON Rewards Now #TON#Hipo Hipo has launched a new feature in their app that allows users to track staking rewards for TON and HPO airdrops. This includes viewing rewards per round, total accumulated rewards, and estimated yearly earnings. Users can now easily monitor their progress and contribute to Hipo's TVL. Source: link @tonlines

Hashtags

TONlines – News

@tonlines · Post #7652 · 30.11.2025 г., 12:07

Hipo: New hTON Rewards Now Available #TON#Hipo Hipo has launched its new hTON rewards system, allowing stakers to earn boosted HPO rewards alongside regular TON staking yields. Members can track and withdraw their rewards in Hipo Club, with the potential to increase rewards by up to 10 times based on club level. Source: link @tonlines

Hashtags

TONlines – News

@tonlines · Post #7387 · 27.05.2025 г., 11:54

Hipo: Launching HPO and Hipo Fund #Hipo#TON Hipo announces the launch of HPO and Hipo Fund to foster sustainable, community-owned growth. A recent blog post elaborates on their role in ensuring Hipo’s long-term success. Source: link @tonlines

Hashtags

TONlines – News

@tonlines · Post #7386 · 27.05.2025 г., 10:43

Hipo: Wallet Security Upgraded #Hipo#TON Hipo has enhanced the security of the Hipo Fund wallet by upgrading it to a multisig address, following a similar upgrade of the HPO tokenomics wallets. A portion of the funds remains in the old single-signature wallet for operational needs. Both wallets can be tracked on-chain via Hipo Docs. Source: link @tonlines

Hashtags

TONlines – News

@tonlines · Post #7370 · 26.05.2025 г., 09:06

Hipo Unveils Redesigned Website #Hipo#TON Hipo has launched a redesigned website to better illustrate its mission and community involvement. The new platform provides detailed insights into Hipo’s projects and invites feedback from visitors. Explore the new website at hipo.finance. Source: link @tonlines

Hashtags

TONlines – News

@tonlines · Post #7273 · 19.05.2025 г., 10:14

⚡️Hipo: HPO Tokenomics Wallets Security Upgrade #Hipo#TON The Hipo channel announced an upgrade of the HPO tokenomics wallets to multisig addresses to enhance security. This move ensures a committed approach to transparency, allowing users to track wallet activities on-chain through Hipo Docs. Source: link @tonlines

Hashtags

TONlines – News

@tonlines · Post #7246 · 16.05.2025 г., 17:22

Hipo Fund Launches in the TON Community #TON#Hipo Hipo Fund has been introduced in the TON Community as the first fully transparent, on-chain investment fund, focusing on community-centric investing within the TON ecosystem. Source: link @tonlines

Hashtags

TONlines – News

@tonlines · Post #7223 · 15.05.2025 г., 11:57

Hipo: Launch of the Hipo Club #Hipo#TON Hipo has launched the Hipo Club as a strategic initiative to strengthen the community around HPO. Their latest blog post details the experiences and lessons learned during the formation of Hipo Gang and the launch of HPO. Source: link @tonlines

Hashtags

TONlines – News

@tonlines · Post #7194 · 13.05.2025 г., 12:28

⚡️Hipo: Now Available on MyTonWallet Explore Section #TON#Hipo Hipo is now listed in the Explore section of MyTonWallet, the first multichain wallet built on TON. With over 9 million users, MyTonWallet offers a secure and user-friendly experience, boasting features like a swap aggregator for optimal token exchange rates. Source: link @tonlines

Hashtags

TONlines – News

@tonlines · Post #7193 · 13.05.2025 г., 12:13

⚡️ Hipo Joins MyTonWallet Explore Section #Hipo#TON Hipo Protocol has been added to the Explore section of MyTonWallet, a multichain wallet on TON with over 9 million users. This integration enhances access to Hipo’s features, including open-source liquid staking, within a secure and user-friendly environment. Source: link @tonlines

Hashtags

TONlines – News

@tonlines · Post #6870 · 21.04.2025 г., 08:55

⚡️Hipo: Exclusive HPO OTC for Strategic Investors #TON#Hipo Hipo is offering a limited round of HPO OTC deals for major investors and VCs. These deals will support the Hipo ecosystem by contributing directly to the on-chain Hipo Fund. This opportunity emphasizes transparent and community-first growth on the TON network. Source: link @tonlines

Hashtags

TONlines – News

@tonlines · Post #6794 · 16.04.2025 г., 11:13

Celebrate Hipo Verification with a Giveaway! #Hipo#TON Hipo has announced a giveaway of 5,000 HPO to celebrate the verification of their Telegram channel. Ten lucky winners will receive 500 HPO each by participating with a GIF, photo, or meme in the comments. Hipo’s socials, including Telegram, X, and YouTube, are now verified, ensuring safer engagement for the community. Source: link @tonlines

Hashtags

ПретходнаСтраница 1 од 3Следна