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

Резултати

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

Пребарај: #lostdogs

当前筛选 #lostdogs清除筛选
🏆 Premium, NFT, Tokens

@giiveaways · Post #2686 · 07.08.2024 г., 14:52

🐶Lost Dogs:The Way👣 Today we need to choose the “average” card. Will Rex go on the expedition? 1. Expedition is On🧗‍♂️ 2. Expedition is Off🚫 3. He Went Alone🌲 I think He Went Alone🌲 will be the average choice. 👉Let’s join the next battle! Share your thoughts in the comments! ➖ 📣Stay tuned! Subscribe! ➖ #lostdogs#crypto#cryptogame

🏆 Premium, NFT, Tokens

@giiveaways · Post #2666 · 06.08.2024 г., 16:15

🐶Lost Dogs: The Way 👣 Today we need to choose the “average” card. How will the dogs deal with the infected? 1. Quarantine 🧪 2. Do Nothing 🛑 3. Kill the Infected ⚔️ I think Quarantine 🧪will be the average choice. 👉Let’s join the next battle! Share your thoughts in the comments! ➖ 📣Stay tuned! Subscribe! ➖ #lostdogs#crypto#cryptogame ➖

🏆 Premium, NFT, Tokens

@giiveaways · Post #3083 · 11.09.2024 г., 12:53

🐶Lost Dogs:The Way - 🏆Last Round’s Winner: Survival Kit🧰 📝New Challenge: What will the Cat do next? (Find the unpopular card) 1. To Wash 🧼 2. Track Down Gavkus 🐾 3. Summon Darkness 🌑 🔍 Analyze carefully before making your choice! 🔔Subscribe👉Join Lost Dogs ————————————————— #lostdogs#crypto#dogs

🐶Lost Dogsis officially out! This is not just another slipper. This is a community driven story where you can mine the new $WOOF token. The season will last only 6 weeks! 🤪Join our clan, as usual we will try to rise to the top and earn more $NOT The team has released a useful guide, thanks to which you can understand the game and its interesting plot, which you control yourself! Play here @lost_dogs_bot #Notcoin#GameFi#LostDogs#TON#NOT

🏆 Premium, NFT, Tokens

@giiveaways · Post #3004 · 03.09.2024 г., 13:46

🐶Lost Dogs:The Way - 🏆Last Round’s Winner: Fireworks🎆 📝New Challenge: Which tactic to choose? (Find an average card) 1. Surround 🌀 2. Frontal Attack 🚀 3. Fake Retreat 🎭 🔍Analyze carefully before making your choice! 🔔Subscribe👉Join Lost Dogs ————————————————— #lostdogs#crypto#dogs #cryptogame#nftgaming

🏆 Premium, NFT, Tokens

@giiveaways · Post #2984 · 01.09.2024 г., 11:56

🐶Lost Dogs:The Way - 🏆 Last Round’s Winner: Decryption Machine 📜New Challenge: How to handle the new information? (Find the average card) 1. Tell Everyone 📢 2. Hide the Truth 🔥 3. Defuse 🛡️ 🔍Analyze carefully before making your choice! 🔔Subscribe👉Join Lost Dogs ————————————————— #lostdogs#crypto#dogs #cryptogame#nftgaming

🏆 Premium, NFT, Tokens

@giiveaways · Post #2928 · 27.08.2024 г., 16:22

🐶Lost Dogs:The Way - 🥇 Last Round’s Winner: The winning card in the last game was Go Underground🌿 🚀New Challenge: What truth will the Resistance reveal? (Find the average card) 1. Greed of the Cult 🪙 2. About Religious Lies 📖 3. How to Resist 🛠 🔍Analyze carefully before making your choice! 🔔Subscribe👉Join Lost Dogs ————————————————— #lostdogs#crypto#dogs #cryptogame#nftgaming

🏆 Premium, NFT, Tokens

@giiveaways · Post #2911 · 26.08.2024 г., 18:14

🐶Lost Dogs:The Way - 🥇 Last Round’s Winner: The winning card in the last game was Kidnap🐾 🚀New Challenge: How can Resistance continue the fight? (Find the unpopular card) 1. Invite Newcomers 👥 2. Go Underground 🌿 3. Pirate Radio 🎙 🔍Analyze carefully before making your choice! 🔔Subscribe👉Join Lost Dogs ————————————————— #lostdogs#crypto#dogs #cryptogame#nftgaming

🏆 Premium, NFT, Tokens

@giiveaways · Post #2884 · 25.08.2024 г., 12:11

🐶Lost Dogs:The Way - 🏆 Last Round’s Winner: The winning card in the last game was Fend Off in Battle! 🛡️ 🚀New Challenge: How should the Resistance Dogs handle the newly born mutant messiah? (Find the average card) 👣 1. Kidnap 🐾 2. Kill ⚔️ 3. Unveil the Origin 🔍 Analyze carefully before making your choice!🧐 🔔Subscribe👉Join Lost Dogs ————————————————— #lostdogs#crypto#dogs #cryptogame#nftgaming

🏆 Premium, NFT, Tokens

@giiveaways · Post #2869 · 24.08.2024 г., 12:10

🐶Lost Dogs:The Way - 🏆 Last Round’s Winner: The winning card in the last game was Wisdom! 👣 🚀New Challenge: How will they rescue Genghis Gaf, and will they? 1. Fend Off in Battle🔥 2. Stay Low 🏠 3. Rescue Secretly 🤘 Analyze carefully before making your choice! 🔔Subscribe👉Join Lost Dogs ————————————————— #lostdogs#crypto#dogs #cryptogame#nftgaming

🏆 Premium, NFT, Tokens

@giiveaways · Post #2836 · 22.08.2024 г., 20:05

🐶🐶Lost Dogs: The Way - 🏆Last Round’s Winner: The winning card in the last game was Fight Back!👣 🚀New Challenge: What are the dogs expecting from their beloved wizard's performance? 1. Underground Firework 🎆 2. New Day 🌅 3. Existence’s Purpose 🔮 Analyze carefully before making your choice! 🔔Subscribe👉Join Lost Dogs ————————————————— #lostdogs#crypto#dogs #cryptogame#nftgaming

🏆 Premium, NFT, Tokens

@giiveaways · Post #2824 · 21.08.2024 г., 19:25

🐶Lost Dogs: The Way - 🏆Last Round’s Winner: The winning card in the last game was Secret Comlink! 👣 🚀New Challenge: What should the dogs do during the raid? 1. Fight Back🥊 2.Run Away🏃‍♂️ 3.Negotiate🤝 Analyze carefully before making your choice! 🔔Subscribe👉Join Lost Dogs ————————————————— #lostdogs#crypto#dogs #cryptogame#nftgaming

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