Можно ли в 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
⚠️
⚠️
⚠️
⚠️
⚠
🔔AMA ANNOUNCEMENT
🗣We are pleased to announce Our #BinanceLive AMA with BOSS || 5th January 2025 at ( 1:00 PM UTC)
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
⏳ Time : 5th January , 2026 at (1:00 PM UTC)
🏠 Venue
🔶Binance Live
💎 Reward : 100$ USDT
🤵♂️Guest : Project Team
➡️There will be 3 segments. Last approximately for 45 minutes - 1 hours.
🟢Segment 1: Introduction Questions
🟢Segment 2: Twitter Questions
🟢Segment 3: Live Questions
📌Rules to follow AMA:
✅ Join
✉️CryptoFight
✉BOSS
✅Like & Retweet
✅Twitter Post
✅ Follow
📝CryptoFight &
📝Clarnium on Twitter
📝 Ask Your Questions ( Here )
🔔 Set Reminder :
⏰ Must Join " BOSS Social Media Links :
🌐Website
⏰ Must JoinCrypto Fight Community :
✉️Telegram
✉️Channel
📝Twitter
🔶Binance Live
*️⃣Linktree
💥If You Want To Promote Your Project Or AMA Proposal
📞DM @Ryan_Fight
⚠️
⚠️
⚠️
⚠️
⚠
🔔AMA ANNOUNCEMENT
🗣We are pleased to announce our #BinanceLive AMA with Stake Cash Coin(SACO) || 1st December, 2025 at ( 2:00 PM UTC)
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
⏳ Time : 1st December , 2025 at (2:00 PM UTC)
🏠 Venue
🔶Binance Live
💎 Reward : 100$ USDT
🤵♂️Guest : Project Team
➡️There will be 3 segments. Last approximately for 45 minutes - 1 hours.
🟢Segment 1: Introduction Questions
🟢Segment 2: Twitter Questions
🟢Segment 3: Live Questions
📌Rules to follow AMA:
✅ Join
✉️CryptoFight
✉Stake Cash Coin(SACO)
✅Like & Retweet
✅Twitter Post
✅ Follow
📝CryptoFight &
📝Stake Cash Coin(SACO) on Twitter
📝 Ask Your Questions ( Here )
🔔 Set Reminder :
https://www.binance.com/live/video?roomId=2285385
⏰ Must Join " Stake Cash Coin(SACO)" Social Media Links :
❌Twitter
✉️Telegram
🌐Website
📷Instagram
⏰ Must JoinCrypto Fight Community :
✉️Telegram
✉️Channel
📝Twitter
🔶Binance Live
*️⃣Linktree
💥If You Want To Promote Your Project Or AMA Proposal
📞DM @Ryan_Fight
⚠️
⚠️
⚠️
⚠️
⚠
🔔AMA ANNOUNCEMENT
🗣We are pleased to announce our #BinanceLive AMA with AIO protocol || 21th November , 2025 at ( 1:00 PM UTC)
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
⏳ Time : 21th November , 2025 at (1:00 PM UTC)
🏠 Venue
🔶Binance Live
💎 Reward : 100$ USDT
🤵♂️Guest : Chloe & Jade
➡️There will be 3 segments. Last approximately for 45 minutes - 1 hours.
🟢Segment 1: Introduction Questions
🟢Segment 2: Twitter Questions
🟢Segment 3: Live Questions
📌Rules to follow AMA:
✅ Join
✉️CryptoFight
✉AIO protocol
✅Like & Retweet
✅Twitter Post
✅ Follow
📝CryptoFight &
📝AIO protocol on Twitter
📝 Ask Your Questions ( Here )
🔔 Set Reminder :
https://www.binance.com/en/live/video?roomId=2283711
⏰ Must Join " AIO protocol" Social Media Links :
❌Twitter
✉️Telegram
⏰ Must JoinCrypto Fight Community :
✉️Telegram
✉️Channel
📝Twitter
🔶Binance Live
*️⃣Linktree
💥If You Want To Promote Your Project Or AMA Proposal
📞DM @Ryan_Fight
⚠️
⚠️
⚠️
⚠️
⚠
🔔AMA ANNOUNCEMENT
🗣We are pleased to announce our #BinanceLive AMA with GIGGLE FUND || 16th November , 2025 at ( 6:00 PM UTC)
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
⏳ Time : 16th November , 2025 at (6:00 PM UTC)
🏠 Venue
🔶Binance Live
💎 Reward : 100$ USDT
🤵♂️Guest :
➡️There will be 3 segments. Last approximately for 45 minutes - 1 hours.
🟢Segment 1: Introduction Questions
🟢Segment 2: Twitter Questions
🟢Segment 3: Live Questions
📌Rules to follow AMA:
✅ Join
✉️CryptoFight
✉GIGGLE FUND
✅Like & Retweet
✅Twitter Post
✅ Follow
📝CryptoFight &
📝GIGGLE FUND on Twitter
📝 Ask Your Questions ( Here )
🔔 Set Reminder :
⏰ Must Join " GIGGLE FUND" Social Media Links :
❌Twitter
🔥Website
✉️Telegram
⏰ Must JoinCrypto Fight Community :
✉️Telegram
✉️Channel
📝Twitter
🔶Binance Live
*️⃣Linktree
💥If You Want To Promote Your Project Or AMA Proposal
📞DM @Ryan_Fight
⚠️
⚠️
⚠️
⚠️
⚠
🔔AMA ANNOUNCEMENT
🗣We are pleased to announce our #BinanceLive AMA with Usd1swap || 13th November , 2025 at ( 1:00 PM UTC)
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
⏳ Time : 13th November , 2025 at (1:00 PM UTC)
🏠 Venue
🔶Binance Live
💎 Reward : 100$ USDT
🤵♂️Guest :
➡️There will be 3 segments. Last approximately for 45 minutes - 1 hours.
🟢Segment 1: Introduction Questions
🟢Segment 2: Twitter Questions
🟢Segment 3: Live Questions
📌Rules to follow AMA:
✅ Join
✉️CryptoFight
✉Usd1swap
✅Like & Retweet
✅Twitter Post
✅ Follow
📝CryptoFight &
📝Usd1swap on Twitter
📝 Ask Your Questions ( Here )
🔔 Set Reminder :
https://www.binance.com/en/live/video?roomId=2283379
⏰ Must Join " Usd1swap" Social Media Links :
❌Twitter
🔥Website
⏰ Must JoinCrypto Fight Community :
✉️Telegram
✉️Channel
📝Twitter
🔶Binance Live
*️⃣Linktree
💥If You Want To Promote Your Project Or AMA Proposal
📞DM @Ryan_Fight
⚠️
⚠️
⚠️
⚠️
⚠
🔔AMA ANNOUNCEMENT
🗣We are pleased to announce our #BinanceLive AMA with MetaPi || 10th November , 2025 at ( 2:00 PM UTC)
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
⏳ Time : 10th November , 2025 at (2:00PM UTC)
🏠 Venue
🔶Binance Live
💎 Reward : 100$ USDT
🤵♂️Guest : Caitlyn
➡️There will be 3 segments. Last approximately for 45 minutes - 1 hours.
🟢Segment 1: Introduction Questions
🟢Segment 2: Twitter Questions
🟢Segment 3: Live Questions
📌Rules to follow AMA:
✅ Join
✉️CryptoFight
✉MetaPi
✅Like & Retweet
✅Twitter Post
✅ Follow
📝CryptoFight &
📝MetaPi on Twitter
📝 Ask Your Questions ( Here )
🔔 Set Reminder :
https://www.binance.com/en/live/video?roomId=2283001
⏰ Must Join " MetaPi" Social Media Links :
❌Twitter
🔥Website
⏰ Must JoinCrypto Fight Community :
✉️Telegram
✉️Channel
📝Twitter
🔶Binance Live
*️⃣Linktree
💥If You Want To Promote Your Project Or AMA Proposal
📞DM @Ryan_Fight
⚠️
⚠️
⚠️
⚠️
⚠
🔔AMA ANNOUNCEMENT
🗣We are pleased to announce our #BinanceLive AMA with MetaPi || 14th October , 2025 at ( 2:00 PM UTC)
🔠
🔠
🔠
🔠🔠🔠
🔠🔠
🔠🔠
⏳ Time : 14th October , 2025 at (2:00 PM UTC)
🏠 Venue
🔶Binance Live
💎 Reward : 100$ USDT
🤵♂️Guest : Caitlyn
➡️There will be 3 segments. Last approximately for 45 minutes - 1 hours.
🟢Segment 1: Introduction Questions
🟢Segment 2: Twitter Questions
🟢Segment 3: Live Questions
📌Rules to follow AMA:
✅ Join
✉️CryptoFight
✉MetaPi
✅Like & Retweet✅Twitter Post
✅ Follow
📝CryptoFight &
📝MetaPi on Twitter
📝 Ask Your Questions ( Here )
🔔 Set Reminder :
https://www.binance.com/live/video?roomId=2280210
⏰ Must Join " MetaPi" Social Media Links :
❌Twitter🔥Website
⏰ Must JoinCrypto Fight Community :
✉️Telegram✉️Channel
📝Twitter🔶Binance Live
*️⃣Linktree
💥If You Want To Promote Your Project Or AMA Proposal📞DM @Ryan_Fight
⚠️
⚠️
⚠️
⚠️
⚠
🔔AMA ANNOUNCEMENT
🗣We are pleased to announce our #BinanceLive AMA with Biokript-Bro || 09th October , 2025 at ( 3:00 PM UTC)
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
⏳ Time : 09th October , 2025 at (3:00 PM UTC)
🏠 Venue
🔶Binance Live
💎 Reward : 100$ USDT
🤵♂️Guest : Adnan Alisic, CEO, Adnan_Biokript
➡️There will be 3 segments. Last approximately for 45 minutes - 1 hours.
🟢Segment 1: Introduction Questions
🟢Segment 2: Twitter Questions
🟢Segment 3: Live Questions
📌Rules to follow AMA:
✅ Join
✉️CryptoFight
✉Biokript-Bro
✅Like & Retweet
✅Twitter Post
✅ Follow
📝CryptoFight &
📝Biokript-Bro on Twitter
📝 Ask Your Questions ( Here )
🔔 Set Reminder :
https://www.binance.com/en/live/video?roomId=2280011
⏰ Must Join " Biokript-Bro" Social Media Links :
❌Twitter
✉️Telegram
🔥Website
⏰ Must JoinCrypto Fight Community :
✉️Telegram
✉️Channel
📝Twitter
🔶Binance Live
*️⃣Linktree
💥If You Want To Promote Your Project Or AMA Proposal
📞DM @Ryan_Fight
⚠️
⚠️
⚠️
⚠️
⚠
🔔AMA ANNOUNCEMENT
🗣We are pleased to announce our #BinanceLive AMA with "CDL" at 11th February 2025 at ( 4:PM, UTC)
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
⏳ Time : 11th February 2025 ( 4: PM, UTC)
🏠 Venue
🔶Binance Live
💎 Reward : 50$ USDT
🤵♂️Guest : CDL Team
➡️There will be 3 segments. Last approximately for 45 minutes - 1 hours.
🟢Segment 1: Introduction Questions
🟢Segment 2: Twitter Questions
🟢Segment 3: Live Questions
📌Rules to follow AMA:
✅ Join
✉️CryptoFight
✉CDL
✅Like & Retweet
✅Twitter Post
✅ Follow
📝CryptoFight &
📝CDL on Twitter
📝 Ask Your Questions ( Here )
🔔 Set Reminder :
https://www.binance.com/en/live/video?roomId=2249344
⏰ Must Join "CDL" Social Media Links :
✉️Telegram
📝Twitter
🌐Website
⏰ Must JoinCrypto Fight Community :
✉️Telegram
✉️Channel
📝Twitter
🔶Binance Live
*️⃣Linktree
💥If You Want To Promote Your Project Or AMA Proposal
📞DM @Ryan_Fight
⚠️
⚠️
⚠️
⚠️
⚠
🔔AMA ANNOUNCEMENT
🗣We are pleased to announce our #BinanceLive AMA with "EvolveToken" at 3th February 2025 at ( 2:PM, UTC)
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
⏳ Time : 3th February 2025 ( 2:00 PM, UTC)
🏠 Venue
🔶Binance Live
💎 Reward : 100$ USDT
🤵♂️Guest : Seth Founder Of Evolve
➡️There will be 3 segments. Last approximately for 45 minutes - 1 hours.
🟢Segment 1: Introduction Questions
🟢Segment 2: Twitter Questions
🟢Segment 3: Live Questions
📌Rules to follow AMA:
✅ Join
✉️CryptoFight
✉EvolveToken
✅Like & Retweet
✅Twitter Post
✅ Follow
📝CryptoFight &
📝EvolveToken on Twitter
📝 Ask Your Questions ( Here )
🔔 Set Reminder :
https://www.binance.com/en/live/video?roomId=2248252&utm_campaign=binance_live
⏰ Must Join "EvolveToken" Social Media Links :
✉️Telegram
📝Twitter
🌐Website
⏰ Must JoinCrypto Fight Community :
✉️Telegram
✉️Channel
📝Twitter
🔶Binance Live
*️⃣Linktree
💥If You Want To Promote Your Project Or AMA Proposal
📞DM @Ryan_Fight
⚠️
⚠️
⚠️
⚠️
⚠
🔔AMA ANNOUNCEMENT
🗣We are pleased to announce our #BinanceLive AMA with "StohnCoin" at 6th February 2025 at (3 PM, UTC)
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
⏳ Time : 6th February 2025 ( 3:00 PM, UTC)
🏠 Venue
🔶Binance Live
💎 Reward : 100$ USDT
🤵♂️Guest : Ing. Jozef Libant - CEO / Brett Weigel - COO / Jason Stanley - CIO / Alexander Almkvist - CTO
➡️There will be 3 segments. Last approximately for 45 minutes - 1 hours.
🟢Segment 1: Introduction Questions
🟢Segment 2: Twitter Questions
🟢Segment 3: Live Questions
📌Rules to follow AMA:
✅ Join
✉️CryptoFight
✅Like & Retweet
✅Twitter Post
✅ Follow
📝CryptoFight &
📝StohnCoin on Twitter
📝 Ask Your Questions ( Here )
🔔 Set Reminder :
https://www.binance.com/en/live/video?roomId=2248211
⏰ Must Join "StohnCoin" Social Media Links :
📝Twitter
🌐Website
⏰ Must JoinCrypto Fight Community :
✉️Telegram
✉️Channel
📝Twitter
🔶Binance Live
*️⃣Linktree
💥If You Want To Promote Your Project Or AMA Proposal
📞DM @Ryan_Fight
⚠️
⚠️
⚠️
⚠️
⚠
🔔AMA ANNOUNCEMENT
🗣We are pleased to announce our #BinanceLive AMA with "POPG" at 21th February 2025 at ( 12 PM, UTC)
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
🔠
⏳ Time : 21th February 2025 ( 12 PM, UTC)
🏠 Venue
🔶Binance Live
💎 Reward : 100$ USDT
🤵♂️Guest : Petra Apostolovic - PR & Community and Gabriel Raimundi - Marketing
➡️There will be 3 segments. Last approximately for 45 minutes - 1 hours.
🟢Segment 1: Introduction Questions
🟢Segment 2: Twitter Questions
🟢Segment 3: Live Questions
📌Rules to follow AMA:
✅ Join
✉️CryptoFight
✉POPG
✅Like & Retweet
✅Twitter Post
✅ Follow
📝CryptoFight &
📝POPG on Twitter
📝 Ask Your Questions ( Here )
🔔 Set Reminder :
https://www.binance.com/en/live/video?roomId=2247598
⏰ Must Join "POPG" Social Media Links :
✉️Telegram
📝Twitter
🌐Website
⏰ Must JoinCrypto Fight Community :
✉️Telegram
✉️Channel
📝Twitter
🔶Binance Live
*️⃣Linktree
💥If You Want To Promote Your Project Or AMA Proposal
📞DM @Ryan_Fight