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

Резултати

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

Пребарај: #gatto

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

@tonlines · Post #7346 · 23.05.2025 г., 14:36

Gatto Official Channel: Weekend Tournament and PvP Event #Gatto#TON Gatto is hosting a weekend tournament alongside a PvP event against its developers, launching on May 23. Players will have the chance to win various rewards by competing in both events, with the tournament ending on May 26 and the PvP event concluding on May 23. Source: link @tonlines

Hashtags

TONlines – News

@tonlines · Post #7213 · 14.05.2025 г., 14:31

Support Gatto in Telegram Apps Center Voting #Telegram#Gatto Gatto | Official Channel encourages users to vote for the Gatto app in the Telegram Apps Center. By participating, users can win Telegram Gifts or Telegram SBT and help raise their favorite app to the top. Source: link @tonlines

TONlines – News

@tonlines · Post #7429 · 29.05.2025 г., 09:23

⚡️Gatto Announces Temporary NFT Feature Downtime #NFT#Gatto Gatto | Official Channel (18+) informs users of a temporary halt to NFT functionality, citing ongoing technical resolutions which will last more than a day. Users are advised not to purchase Gattomon Eggs created between 5:00 p.m. and 6:30 p.m. UTC due to potential game recognition issues. Source: link @tonlines

Hashtags

TONlines – News

@tonlines · Post #7427 · 28.05.2025 г., 20:01

⚡️Gatto: NFT Minting Temporarily Unavailable #NFT#Gatto Gatto announces that NFT minting is currently on hold. Users are advised not to create NFT pets and eggs to avoid permanent loss. Updates will be shared once technical work concludes. Source: link @tonlines

Hashtags

TONlines – News

@tonlines · Post #7697 · 03.12.2025 г., 15:46

Gatto | Official Channel: Creative Contest Announcement #Gatto#GTON Gatto | Official Channel has announced a creative contest to celebrate a birthday, inviting talented individuals to participate by creating drawings, stories, and crafts dedicated to Gatto. Participants are categorized by age, with the chance to win $GTON rewards. Submissions are open until December 8th. Source: link @tonlines

Hashtags

TONlines – News

@tonlines · Post #6778 · 15.04.2025 г., 13:50

⚡️Gatto Official Channel: PvP Battle Event with Rewards #GTON#Gatto The Gatto Official Channel invites players to join a special PvP event starting at 14:00 UTC. Participants who defeat the GTeam in consecutive battles can earn various rewards, including Silver Coins, Legendary Gattoboxes, and more. The event takes place exclusively on the European server and runs until April 15, 15:00 UTC. Source: link @tonlines

Hashtags

TONlines – News

@tonlines · Post #7394 · 27.05.2025 г., 18:20

⚡️Gatto: Temporary Unavailability of the Game #Gatto#game The Gatto team has announced that the game is currently unavailable due to server issues. They are actively working to resolve the problems, and the game will be restored soon. Source: link @tonlines

Hashtags

TONlines – News

@tonlines · Post #7267 · 18.05.2025 г., 19:12

Gatto: Upcoming Technical Works Announced #Gatto#game Mr. Chipmunkus will be performing technical work on the Gatto game starting at 20:30 UTC. Although the game will remain accessible, players might encounter some bugs during this period. Source: link @tonlines

Hashtags

TONlines – News

@tonlines · Post #7118 · 08.05.2025 г., 19:37

Expand Your Play Area with Gatto Official Channel! #Gatto#game Gatto Official Channel introduces a new opportunity to expand the playing field from 40 to 42 squares by inviting friends. Players can unlock new plain and ice biomes with eggs after their friends complete training by Sage Moc. Source: link @tonlines

Hashtags

TONlines – News

@tonlines · Post #6987 · 30.04.2025 г., 14:43

Technical Update at Gatto | Official Channel #Gatto#game Gatto | Official Channel has scheduled technical work with Mr. Chipmunkus. Players may experience some bugs until the game operations return to normal. Source: link @tonlines

Hashtags

TONlines – News

@tonlines · Post #6955 · 29.04.2025 г., 08:12

Gatto: Ongoing Technical Works #Gatto#game Gatto is undergoing technical maintenance by Mr. Chipmunkus. Though the game remains accessible, players might encounter some bugs until everything is fully restored. Source: link @tonlines

Hashtags

TONlines – News

@tonlines · Post #6925 · 24.04.2025 г., 12:42

⚡️Gatto: Temporary Downtime for Technical Maintenance #Gatto#game Gatto | Official Channel announces upcoming technical maintenance by Mr. Chipmunkus after mine completion. The game will be unavailable today from 13:00 UTC. Source: link @tonlines

Hashtags

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