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

Резултати

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

Пребарај: #staking

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

@tonlines · Post #6934 · 28.04.2025 г., 09:08

⚡️Gatto Official Channel: April $GTON Staking Rewards Announced #$GTON #staking Gatto Official Channel has completed the April $GTON staking. Participants have received various rewards including Duckzills and gattoboxes. Long-term token retention awards are also being given for the first time, with new staking starting May 1. Source: link @tonlines

Hashtags

TONlines – News

@tonlines · Post #7675 · 02.12.2025 г., 06:41

⚡️Hipo: Maximize Your Staking Rewards with TON and HPO #TON#staking Hipo offers one of the highest staking reward rates in the TON ecosystem, allowing users to earn both TON and HPO. The dual reward system enhances long-term value for HPO holders and strengthens Hipo’s TVL. Source: link @tonlines

Hashtags

TONlines – News

@tonlines · Post #7293 · 20.05.2025 г., 12:28

bemo | TON Staking Glossary for Beginners and Pros #staking#TON The bemo channel provides a comprehensive glossary on staking in TON, covering essential terms like slashing, LST, APY, and TVL. This resource is perfect for both newcomers and experienced users, with clear explanations and visual aids. Source: link @tonlines

Hashtags

TONlines – News

@tonlines · Post #6801 · 16.04.2025 г., 16:02

EVAA: Leveraged Staking Workshop Tomorrow #TON#staking Join the EVAA workshop tomorrow to learn about leveraged staking, tsTON liquid staking, and how to boost your TON and EVAA XP. The event, hosted by @thetonstakers, promises a beginner-friendly and fun format with real-time interaction. Source: link @tonlines

Hashtags

TONlines – News

@tonlines · Post #7173 · 12.05.2025 г., 13:46

Hipo: Understanding Staking in Crypto #crypto#staking Hipo explores the concept of staking in blockchain networks like TON and Ethereum. The video explains the process of earning rewards through staking, the role of staking pools, and how Hipo enhances security with liquid staking. Source: link @tonlines

🎙Huge potential Staking announcement 👉Investors, those who was interested in staking UpOnly has announced the launch of a new $UPO Staking Round on August 19th 🔥🔥 UpOnly will start a new staking round for $UPO holders on August 19th, at 12:00 UTC. Investors can stake for 30 days, 60 days, or 90 days, with differing returns between 15%-25% APR. Investors can start staking $UPO in the newly opened staking portal today. UpOnly has lowered the staking threshold to as little as 1 UPO. ⏰ 30 days, 60 days, or 90 days staking 🥇 Returns between 15%-25% APR Lets go💥 👉More info: uponlyofficial.substack.com/p/uponly-launches-new-upo-staking-round 👉 Website: https://www.uponly.com/ #staking#promotion

TONlines – News

@tonlines · Post #6843 · 18.04.2025 г., 16:54

Bemo: The Advantage of Liquid Staking #staking#DeFi Bemo introduces liquid staking with bmTON, allowing users to earn rewards while maintaining asset accessibility. This approach integrates seamlessly with TON DeFi and provides strategic benefits for active portfolio managers and yield farmers. Source: link @tonlines

TONlines – News

@tonlines · Post #7648 · 29.11.2025 г., 12:12

Gatto | Official Channel Staking Update for December #staking#GTON Gatto | Official Channel announces a staking event in December for $GTON token holders. Participants can earn various rewards, including exclusive prizes and in-game items, by holding tokens from December 1st to 29th. Source: link @tonlines

TONlines – News

@tonlines · Post #7647 · 29.11.2025 г., 12:12

Gatto: December Staking Rewards Begin December 1 #staking#GTON Gatto | Official Channel announces a new staking initiative for $GTON, starting on December 1 and running until December 29. Participants will be rewarded with various prizes, including game items and tokens, depending on their stake tier. Source: link @tonlines

TONlines – News

@tonlines · Post #7642 · 28.11.2025 г., 15:33

Gatto | Official Channel: November $GTON Staking Completion #staking#GTON The Gatto | Official Channel successfully concluded the November $GTON staking event. Participants maintained their tokens on game balances and earned rewards like gold coins and gattoboxes. The next staking begins on December 1st, with more information on rewards coming soon. Source: link @tonlines

TONlines – News

@tonlines · Post #7436 · 29.05.2025 г., 14:30

Gatto Official Channel: June Staking Rewards for $GTON #GTON#Staking The Gatto Official Channel announces June staking for $GTON, offering substantial rewards for maintaining the token on your game balance. The campaign runs from June 1 to June 30, featuring exclusive prizes not accessible through regular purchase. Source: link @tonlines

TONlines – News

@tonlines · Post #7000 · 01.05.2025 г., 08:01

⚡️Gatto Official Channel: Start of $GTON Staking #GTON#staking Gatto Official Channel announces the beginning of $GTON staking, with the first snapshot scheduled for today at 09:00 UTC. Players are encouraged to top up their game balance and hold $GTON until the end of staking on May 30 to receive rewards. Random balance cuts will occur daily, and details about rules and rewards can be accessed online. Source: link @tonlines

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