Можно ли в 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
😁2 on 1 by Nicholas Meregali😁
➡️The 2-on-1 guard is one of the most reliable and beginner-friendly guards in jiu-jitsu. You don’t need high skill, complex movements, or years of experience to make it work.
➡️Why? Because the moment you pull the opponent’s arm across your center line, you take away their athletic power. Their ability to pressure, explode, or pass your guard drops instantly. This creates a stable, safe guard that works against any belt, any size, and any level of opponent.
$197😍$19.99😍
❗️Channel Info and FAQ (MUST CHECK BEFORE BUY)❗️
📱Payment: 📱📱📱
💰Submeta FOR FREE
👑MasterClass
✈️@bjjfanaticsinstructionals
#NicholasMeregali#Guard#Gi#NewWave
💁♀️Buy
💁♀️
🔥NEW RELEASE🔥
😁Loop Choke by Nicholas Meregali😁
➡️The Loop Choke is one of the most powerful and underrated submissions in Jiu-Jitsu.
➡️In this complete 2.5-hour series, Nicholas breaks down every layer of the position, from the core mechanics to advanced scenarios, covering how to attack from bottom. and top
$127😍$14.99😍
❗️Channel Info and FAQ (MUST CHECK BEFORE BUY)❗️
📱Payment: 📱📱📱
💰Submeta FOR FREE
🌈UFC Picks
👑MasterClass
✈️@bjjfanaticsinstructionals
#NicholasMeregali#Submission#Gi#NewWave
💁♀️Buy
💁♀️
🔥NEW RELEASE🔥
😁Half Guard by Nicholas Meregali😁
➡️Master the Half-Guard with 4 hours of step-by-step instruction designed to give you real control and understanding of this essential position. Learn to dominate in three key stages, Legs, Hips, and Shoulders, using each to solve specific problems and create clear, strategic progress.
➡️We start with the core concept of Camping, teaching you how to stabilize your position, manage pressure, and control posture through precise body placement over your opponent’s shields, hips, and frames, making your base extremely hard to off-balance.
$197😍$19.99😍
❗️Channel Info and FAQ (MUST CHECK BEFORE BUY)❗️
📱Payment: 📱📱📱
💰Submeta FOR FREE
🌈UFC Picks
👑MasterClass
✈️@bjjfanaticsinstructionals
#NicholasMeregali#NewWave#Gi#HalfGuard
💁♀️Buy
💁♀️
🔥NEW RELEASE🔥
😁Back Take by Nicholas Meregali😁
➡️Back Take System is a complete positional framework designed to teach you how to expose, enter, secure and finish the back with calm precision.
➡️Every movement inside this system is rooted in structure, balance manipulation, and mechanical advantage, allowing you to create openings without speed, explosiveness or risk.
$127😍$14.99😍
❗️Channel Info and FAQ (MUST CHECK BEFORE BUY)❗️
📱Payment: 📱📱📱
💰Submeta FOR FREE
👑MasterClass
✈️@bjjfanaticsinstructionals
#NicholasMeregali#Attacks#Gi#NewWave
💁♀️Buy
💁♀️
😁The Complete Jiu-Jitsu System Bundle by Nicholas Meregali😁
➡️This bundle gives you four complete courses, Mount, Half Guard, Lasso Guard, and Deep De La Riva X, all in one package. With over 20 hours of step-by-step instruction from Nicholas Meregali
$447😍$49.99😍
❗️Channel Info and FAQ (MUST CHECK BEFORE BUY)❗️
📱Payment: 📱📱📱
💰Submeta FOR FREE
🌈UFC Picks
👑MasterClass
✈️@bjjfanaticsinstructionals
#NicholasMeregali#Bundle#Gi#NewWave
💁♀️Buy
💁♀️
🔥NEW RELEASE🔥
😁Mount by Nicholas Meregali😁
➡️Master the mount with 6 hours of detailed instruction, starting with the four key stages: High Posture, Low Posture, High Mount, and Low Mount, to strategically adjust decision-making and stability.
➡️Explore Clips (strategic grips) and Head Position as anchors to maintain a firm base, generate constant pressure, and open safe pathways for transitions and submissions.
$197😍$19.99😍
❗️Channel Info and FAQ (MUST CHECK BEFORE BUY)❗️
📱Payment: 📱📱📱
💰Submeta FOR FREE
🌈UFC Picks
👑MasterClass
✈️@bjjfanaticsinstructionals
#NicholasMeregali#NewWave#Gi#Mount
💁♀️Buy
💁♀️
🔥NEW RELEASE🔥
😁Lasso Guard by Nicholas Meregali😁
➡️With approximately 35 instructional videos, this course delivers a complete systematization of the Lasso Guard, one of the most strategic and adaptable guards in Jiu-Jitsu.
➡️Nicholas Meregali presents a highly organized structure that divides the entire guard into key components, making learning clear and progression natural.
$197😍$19.99😍
❗️Channel Info and FAQ (MUST CHECK BEFORE BUY)❗️
📱Payment: 📱📱📱
💰Submeta FOR FREE
🌈UFC Picks
👑MasterClass
✈️@bjjfanaticsinstructionals
#NicholasMeregali#NewWave#Gi#LassoGuard
💁♀️Buy
💁♀️
🔥NEW RELEASE🔥
😁Deep De La Riva X by Nicholas Meregali😁
➡️Deep De La Riva X is a simple and structured guard system developed by Nicholas Meregali, shaped through years of high-pressure experience against world-class opponents at the highest levels of competition.
➡️This course was designed to help you develop a bottom game that’s easy to learn, reliable under pressure, and flexible enough to adapt to any personal style. Whether you’re building your guard from scratch or refining an existing system, Deep De La Riva X will give you the tools to create a connected, repeatable, and intelligent game.
$197😍$19.99😍
❗️Channel Info and FAQ (MUST CHECK BEFORE BUY)❗️
📱Payment: 📱📱📱
💰Submeta FOR FREE
🌈UFC Picks
👑MasterClass
✈️@bjjfanaticsinstructionals
#NicholasMeregali#NewWave#Gi#DeepDeLaRiva
💁♀️Buy
💁♀️
🔥CYBER MONDAY🔥
😍DEAL NO LONGER AVAILABLE😍
Congrats for everyone who redeemed 👨💻 turn notifications ON to stay tuned with future promos.
#NicholasMeregali#GianniGrippo#TainanDalpra
💁♀️Redeem
💁♀️