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

Резултати

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

Пребарај: #speakenglish

当前筛选 #speakenglish清除筛选

We are super excited for you to meet our friend, Bekzod Kholmurodov, an Uzbekistan-born sophomore student at Drexel University, USA this Saturday, at 19:00 Tashkent time! Don’t miss this unique opportunity to learn from someone who has an invaluable experience of coming to the US as an international high school student first, and now is a college student as a El-Yurt Umidi scholar! Invite your friends and get your questions ready!! #UzbeksInAmerica#SpeakEnglish#OneStepAtATime 🇺🇸🤝🇺🇿

BBC Learning English

@english_bbc_learning · Post #3765 · 25.11.2025 г., 10:12

⁣ 🥊 There are quite a few English phrasal verbs with ‘hit’ – here are 5 of them to learn and use. 👋 Have a go at the quiz – and see if you can use any of them in a sentence of your own! (Images: Getty)⁣ ⁣ Extra: Click on our link in bio to learn 4 phrases with 'hit'.⁣ ⁣ #learnenglish#vocab#vocabulary#speakenglish#englishtips ⁣

BBC Learning English

@english_bbc_learning · Post #3912 · 08.02.2026 г., 08:19

Let’s be real: You’ve probably seen a list like this 1,000 times. It looks repetitive, maybe even "dumb." But here is why it actually matters for you: When you only have one word for everything (like "Good"), your brain "glitches" when you're trying to speak fast. You hesitate because you're searching for variety but your "vocabulary folder" is empty. 🧠 The Secret to Speaking Fast:🛫 Fluency isn't about knowing the hardest words; it's about having options. When you have 3-4 ways to say the same thing, your brain doesn't have to stall. It just picks the next available word and keeps the flow going. - #English#SpeakEnglish#EnglishTips#Vocabulary#SpokenEnglish

Daily Channels

@dailychannels · Post #6511 · 28.11.2025 г., 13:00

Group: English Chatting House | Global English Speaking Chat Members: ~4.48K 💢 Username: @english_chatting_house Description: ⭐ Welcome to ECH! English only - global English chat, spoken English practice, fun talks & chill worldwide vibes. Talk English, meet international people, improve fluency, keep it clean. No beef, no hate, no promo. Got any queries? :- @Bilxerian 🏷 Tags: #languages #learnenglish#englishchat#speakenglish#englishgroup#globalchat https://telegramchannels.me/groups/english_chatting_house

BBC Learning English

@english_bbc_learning · Post #3937 · 02.04.2026 г., 15:48

Idiom of the Day! 🚌 Throw someone under the bus Meaning: To blame someone else so you don't get in trouble. Example: "Mark made the mistake, but he threw me under the bus!" 😠 #LearnEnglish#EnglishIdioms#Vocabulary#ESL#EnglishPhrases#SpeakEnglish

BBC Learning English

@english_bbc_learning · Post #3804 · 14.12.2025 г., 07:15

Do you know someone who always thinks that everyone else has a better life than them?! 🙄😅 Scroll through the images to find out how to use ‘the grass is always greener on the other side’ 🌱, and don’t forget to answer the questions on the last slide! ⁣ ⁣ EXTRA: Could walking 7,000 steps a day could improve your mental health? 🚶 Click the link in our bio to find out and learn some useful vocabulary in the process! 📰💚⁣ ⁣ Image: Getty⁣ ⁣ #vocabulary#learnenglish#englishlanguage#expression#idiom#proverb#englishclass#speakenglish

BBC Learning English

@english_bbc_learning · Post #3776 · 29.11.2025 г., 10:17

You know when somebody just WON’T change their ways? 😠 We’ve got an English expression for that! ✅ ⁣ ⁣ Scroll through the images to find out how to use ‘You can’t teach an old dog new tricks.’ ❌🐶 ⁣ ⁣ Can you use it in a sentence – and do you have a similar expression in your language? 👇👇👇⁣ ⁣ MORE: If you'd like to learn some more animal idioms, like 'rabbit on 🐰' or 'as sick as a parrot 🦜', click the link in our bio! ⁣ ⁣ Image: Getty⁣ ⁣ #trick#proverb#learnenglish#vocabulary#learnenglish#englishlanguage#expression#idiom#englishclass#speakenglish ⁣

BBC Learning English

@english_bbc_learning · Post #3809 · 15.12.2025 г., 05:11

Here are 5 linkers that you can add to your conversation to make it flow better and sound more fluent! 1) To be honest – I’m going to give my opinion (even if it’s insulting!) 2) Actually – to correct information or say something surprising 3) Mind you – I’ve just thought of something that contrasts what I was saying 4) By the way – I’m going to introduce a new topic I’ve just remembered 5) Anyway – I’m going to finish the conversation or change topic now Add them to your conversations to help them flow! Which one is your favourite? #learnenglish#speakenglish#vocabulary#bbclearningenglish#britishenglish#formalenglish#linkers#naturalenglish#nativespeakerenglish#conversationskills#ncoversationalenglish

BBC Learning English

@english_bbc_learning · Post #3691 · 21.09.2025 г., 05:35

🚀 Power up your English vocabulary with these FIVE phrasal verbs with ‘pay’! Take a look 👀 and then practise using them right now in the comments! 🤔 Do you know any more phrasal verbs with ‘pay’?⁣ ⁣ (Images: Getty)⁣ ⁣ 🎧 Click on the link in our bio to listen to Neil and Georgie talk about money!⁣ ⁣ #phrasal#phrasalverb#pay#payoff#payout#payup#payfor#learnenglish#vocab#vocabulary#speakenglish#englishtips