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

Резултати

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

Пребарај: #getgems

当前筛选 #getgems清除筛选
☎️ Phoneword

@Morgan · Post #423 · 28.10.2024 г., 05:18

💎Stats in Top3 Collections 💠 + Top Owners #GetGems Date: 2024/10/28 1) Telegram Usernames (Total Volume: 70M TON) Owners: 45,231 Avg. owned: 4.21 Unique Holders: 23.74 % Items / Owners 1: 27,979 2–5: 11,862 6–24: 4,317 25-50: 590 Over 50: 483 2) Anonymous Telegram Numbers (Total Volume: 21M TON) Owners: 45,057 Avg. owned: 3.03 Unique Holders: 32.99 % Items / Owners 1: 30,739 2–5: 11,188 6–24: 2,624 25-50: 271 Over 50: 235 3) TON DNS Domains (Total Volume: ~7M TON) Owners: 35,872 Avg. owned: 3.13 Unique Holders: 31.92 % Items / Owners 1: 26,133 2–5: 7,087 6–24: 2,165 25-50: 269 Over 50: 218 📡@Phoneword

Hashtags

TONlines – News

@tonlines · Post #7631 · 27.11.2025 г., 13:14

Celebrate Thanksgiving with Getgems NFT #Getgems#TON Getgems NFT invites its community to share a holiday toast in their Holiday Drinks collection this Thanksgiving. Participants can win prizes such as Bling Binky and Money Pots by submitting heartfelt comments before November 29. Comments cost 0.5 TON and will be manually approved. Source: link @tonlines

Hashtags

TONlines – News

@tonlines · Post #7282 · 19.05.2025 г., 15:21

Getgems NFT: Selling Subdomains on Getgems #Getgems#TON Getgems NFT now allows TON DNS domain holders to create and sell collections of third-level domains on the Getgems platform. Domain owners can set prices, manage their mini marketplaces, and earn royalties from subdomain transactions. The first such collection has been launched with the Lost Dogs project using the woof.ton domain. Source: link @tonlines

Hashtags

TONlines – News

@tonlines · Post #7278 · 19.05.2025 г., 14:18

Getgems NFT: The Rise of Subdomains #TON#Getgems Getgems NFT discusses the introduction of subdomains on TON DNS. These subdomains offer a new way for domain holders and projects to monetize and create distinct ecosystems. More details on pricing and launch will be shared soon. Source: link @tonlines

Hashtags

TONlines – News

@tonlines · Post #7635 · 27.11.2025 г., 16:22

⚡️Getgems NFT: Gift Fest Launches an Exciting Prize Hunt #Telegram#Getgems Getgems NFT announces the launch of Gift Fest, the largest gift festival on Telegram, featuring 100,000 gifts valued at $400,000. Participants can join by using the festival mini-app to play, merge gifts, and enter weekly raffles, culminating in a main raffle on December 29. Source: link @tonlines

TONlines – News

@tonlines · Post #7603 · 24.11.2025 г., 14:05

New Telegram Gifts at Getgems #Telegram#Getgems Getgems has launched new Telegram Gifts which are now tradable with 0% fees. Users can transfer or purchase items like Bling Binkies, Money Pots, and Pretty Posies through the mini app or website. Source: link @tonlines

TONlines – News

@tonlines · Post #6863 · 20.04.2025 г., 12:23

Getgems NFT: Easter Giveaway for Easter Domain Holders #Telegram#Getgems Getgems NFT is hosting a Flash Easter Giveaway for all holders of Easter-themed Getgems Domains and Telegram Usernames. Participants have a chance to win one of 20 Telegram Gifts totaling 100 TON. Winners will be announced on April 21. Source: link @tonlines

TONlines – News

@tonlines · Post #7638 · 28.11.2025 г., 13:04

⚡️Getgems NFT: Black Friday Raffle Announced #Getgems#NFT The Getgems NFT channel has launched a Black Friday raffle with unique black-background gifts. From November 28 to November 30, users can enter by importing specific collectible items, such as Instant Ramens or Money Pots, via @gemsrelayer. Winners will receive special editions of these items. Source: link @tonlines

Hashtags

TONlines – News

@tonlines · Post #7178 · 12.05.2025 г., 17:00

New Commenting Features on Getgems NFT #Getgems#NFT Getgems NFT introduces a new feature allowing users to make announcements and comments on NFT collections. Messages undergo moderation and can cost 0.5 to 10 TON, depending on the type of collection. Source: link @tonlines

Hashtags

TONlines – News

@tonlines · Post #6967 · 29.04.2025 г., 16:35

Getgems NFT: Celebrate with Your Collector Wrap #Getgems#NFT Getgems NFT celebrates its three-year anniversary by offering users a unique Collector Wrap experience on TON. Connect your wallet to explore your NFT journey, claim a limited-edition anniversary SBT, and create a custom avatar. Source: link @tonlines

Hashtags

TONlines – News

@tonlines · Post #7568 · 21.11.2025 г., 15:22

Getgems NFT: Sticker Digest Unveiled #TON#Getgems#NFT Getgems NFT introduces the Sticker Digest, highlighting notable developments in the TON sticker market. Key updates include the trading success of Goodies with over 250K TON, the pioneering Sticker Pack collections, and recent collaborations within the ecosystem. Enhanced browsing with new filters is now available. Source: link @tonlines

TONlines – News

@tonlines · Post #6840 · 18.04.2025 г., 14:46

Getgems NFT: Marketplace Technical Issues #Getgems#marketplace The Getgems NFT marketplace is currently facing technical difficulties. However, the team is actively working to resolve the issues, and the website will be operational shortly. Source: link @tonlines

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