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

Резултати

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

Пребарај: #commonmistakes

当前筛选 #commonmistakes清除筛选
Journey to Fluency

@fluencyinenglish · Post #7812 · 01.12.2020 г., 20:11

#commonmistakes @fluencyinenglish 💎چند نمونه اشتباه رایچ که خیلی از دوستان مرتکبش میشن رو در اینجا بررسی میکنیم 1⃣هیچ وقت نگید : Praise for her بگید : Praise her 2⃣هیچ وقت نگید : clap to him بگید : clap him 3⃣هیچ وقت نگید : applaud for him بگید :applaud him 4⃣هیچ وقت نگید : Thank for you بگید : Thank you 5⃣هیچ وقت نگید : I respect for him بگید : I respect him 6⃣هیچ وقت نگید : Pray to him بگید : Pray him 7⃣هیچ وقت نگید : Greet for them بگید : Greet them 8⃣هیچ وقت نگید : Speak for her بگید : Speak her 9⃣هیچ وقت نگید :Congratulate for him بگید : Congratulate him 🔟 هیچ وقت نگید :Write for him بگید : Write him @fluencyinenglish

Journey to Fluency

@fluencyinenglish · Post #7403 · 07.11.2019 г., 04:45

#commonmistakes @fluencyinenglish ⚪️At the beginning and in the beginning⚪️ 💎برای بیانِ چیزی که درست در شروع یک رویدادی خاص یا در دوره‌ای معین اتفاق می‌افتد از عبارتِ at the beginning of استفاده می‌کنیم: 🔵 At the beginning of the Civil War Fort Sumter was attacked. 🔵 There's a car chase at the beginning (= at the start of the film). 💎 از عبارتِ in the beginning وقتی استفاده می‌کنیم که بخواهیم بگوییم چیزی در مراحلِ آغازینِ یک رخداد یا در آغازِ دوره‌ای طولانی‌تر اتفاق افتاده است: 🔵 In the beginning the South had some success. (یعنی در اوایلِ جنگِ داخلی) 🔵 I was too shy to speak to her in the beginning. (یعنی در چند ملاقاتِ اولیه‌مان) 💎 باید توجه داشت که پس از in the beginning حرفِ اضافه‌ی of به‌کار نمی‌رود. 💎 کلمه‌ی beginning با دو حرفِ n نوشته می‌شود. @fluencyinenglish

Journey to Fluency

@fluencyinenglish · Post #7248 · 21.07.2019 г., 05:08

#commonmistakes @fluencyinenglish ❇️In comparing two things, the Comparative should be used, The Superlative should not be used. هنگام‌ مقایسه ۲ چیز، از صفات تفضیلی یا همان comparative به کار ببرید. از کاربرد صفات عالی یا همان superlative در این مواقع استفاده نکنید. ❌ Which is the best of the two? ✅ Which is the better of the two? ___________________________ ❇️When two qualities of the same person or thing are compared, the Comparative in 'er' is not used. 'More' is used for this purpose. وقتی خصوصیات یک فرد و یا چیزی را مقایسه می کنیم، بایستی از "more" به جای"er" استفاده کنیم. ❌ He is wiser than brave. ✅ He is more wise than brave. ___________________________ در هنگام استفاده از صفات تفضیلی، بایستی‌مقایسه را با زیر‌ ‌مجموعه های هر دسته بکار‌ببریم. ❌ He is cleverer than any boy in the class. ✅ He is cleverer than any other boy in the class. ___________________________ در هنگام ‌استفاده از صفات عالی، بایستی مقایسه را با دسته اصلی هر موردی‌ بکار‌ببریم. ❌ He is the strongest of all other men. ✅ He is the strongest of all men. __________________________ ❇️Guard against, not from. ❌ : You must guard from bad habits. ✅ : You must guard against bad habits. __________________________ ❇️Omission of the personal pronoun before the infinitive. ❌ I want to tell me the truth. ✅ I want you to tell me the truth. ▪️Express the subject of the infinitive after verbs like want, like, wish, etc , if it is different from that of the main verb. @fluencyinenglish

Journey to Fluency

@fluencyinenglish · Post #7218 · 03.07.2019 г., 03:54

#commonmistakes @fluencyinenglish ⚪️Succeed in + -ing. ❌: Paula succeeded to win the prize. ✅: Paula succeeded in winning the prize. ▪️▪️▪️▪️▪️▪️▪️▪️▪️▪️▪️▪️ ⚪️Take an exam, not give an exam. ❌ : The pupil gave his exam. ✅ : The pupil took his exam. 🔵Note: The teacher gives or sets the exam. The student takes the exam or sits the exam. ▪️▪️▪️▪️▪️▪️▪️▪️▪️▪️▪️▪️ ⚪️To be right or wrong, not to have right or wrong. ❌ : You've right or You've wrong. ✅ : You're right or You're wrong. ▪️▪️▪️▪️▪️▪️▪️▪️▪️▪️▪️▪️ ⚪️Succeed in, not at. ❌ : I hope he'll succeed at his work. ✅ : I hope he'll succeed in his work. 🔵Note: A person succeeds to a property, a title, or an office: Queen Elizabeth II succeeded to the throne in 1952. Also one person can succeed another. ▪️▪️▪️▪️▪️▪️▪️▪️▪️▪️▪️▪️ ⚪️To be busy, not to have work. ❌ : I have much work this morning. ✅ : I'm very busy this morning. 🔵Note: We can say: I have a lot of work to do this morning. @fluencyinenglish

Journey to Fluency

@fluencyinenglish · Post #7105 · 11.05.2019 г., 12:48

#commonmistakes @fluencyinenglish Too much or Very much? 🔴 She likes the cinema too much. He's too much stronger than I am. ✅ She likes the cinema very much. He's very much stronger than I am. 🔵🔵 Use very much instead of much for greater emphasis. Too much denotes an excessive quantity or degree: She ate too much, and felt ill. @fluencyinenglish

Journey to Fluency

@fluencyinenglish · Post #6974 · 19.03.2019 г., 09:10

#commonmistakes @fluencyinenglish 👉Go on (continue) + -ing. ❌: The music went on to play all day. ✅: The music went on playing ail day. ▪️▪️▪️▪️▪️▪️▪️▪️▪️▪️▪️▪️ 👉Mind (object to) + -ing. ❌: Would you mind to open the door? ✅: Would you mind opening the door? ▪️▪️▪️▪️▪️▪️▪️▪️▪️▪️▪️▪️ 👉Practise + -ing. ❌: You must practise to speak English. ✅: You must practise speaking English. ▪️▪️▪️▪️▪️▪️▪️▪️▪️▪️▪️▪️ 👉Remember + -ing. ❌: I don't remember to have seen him. ✅: I don't remember seeing him. Or: ✅I don't remember having seen him. ▪️▪️▪️▪️▪️▪️▪️▪️▪️▪️▪️▪️ 👉Risk + -ing. ❌: We couldn't risk to leave him alone. ✔️: We couldn't risk leaving him alone. ▪️▪️▪️▪️▪️▪️▪️▪️▪️▪️▪️▪️ 👉Stop + -ing. ❌: The wind has almost stopped to blow. ✅: The wind has almost stopped blowing. ▪️▪️▪️▪️▪️▪️▪️▪️▪️▪️▪️▪️ 👉Busy+ -ing. ❌: He was busy to revise the exams. ✅: He was busy revising for the exams. ▪️▪️▪️▪️▪️▪️▪️▪️▪️▪️▪️▪️ 👉Worth + -ing. ❌: Is today's film worth to see? ✅: Is today's film worth seeing? @fluencyinenglish

Journey to Fluency

@fluencyinenglish · Post #6892 · 22.02.2019 г., 05:11

#commonmistakes @fluencyinenglish Prepositions often confused: For for About ❌: The teacher spoke for bad habits. ✅: The teacher spoke about bad habits. Don't use "for" in the sense of "about". The chief use of "about" is to convey the idea of being in favour of. If we say that the teacher spoke for bad habits it's like saying that he/she spoke in favour of bad habits ▪️▪️▪️▪️▪️▪️▪️▪️▪️▪️▪️▪️ Using who, whom, or which after the superlative, instead of that. ❌: It's the best which I've seen. ✅: It's the best (that) I've seen. Use the relative that (not who, whom, or which) after a superlative. It can, however, be omitted. ▪️▪️▪️▪️▪️▪️▪️▪️▪️▪️▪️▪️ Travel by train, etc., not with the train, etc: ❌: He traveled with the train yesterday. ✅: He traveled by train yesterday. Note: We say: by train, by boat, by plane, by bike; also, by land, by sea, by air, by bus; on a bus or in a bus; by car or in a car, by taxi or in a taxi; on horseback, on a donkey, on a bicycle; on foot. ▪️▪️▪️▪️▪️▪️▪️▪️▪️▪️▪️▪️ Conform to, not with. ❌ :'We must conform with the rules. ✅: We must conform to the rules. @fluencyinenglish

Journey to Fluency

@fluencyinenglish · Post #6888 · 21.02.2019 г., 04:55

#commonmistakes @fluencyinenglish ❇️Uses of adverbs 'Much' is used before past participles and Adjectives or Adverbs of comparative degree. 'Very' is used before the present participles and Adjectives and Adverbs of positive degree. ❌ - The news is much surprising. ✅ - The news is very surprising. ❌ - I was very surprised at hearing the news. ✅ - I was much surprised at hearing the news. ▪️▪️▪️▪️▪️▪️▪️▪️▪️▪️▪️▪️ ❇️Prepositions often confused Beautiful for Handsome or Good-looking. ❌ : He's grown into a beautiful young man. ✅ : He's grown into a handsome young man. 👉We usually say that a man is handsome or good-looking, and that a woman is beautiful, lovely, good looking or pretty. ▪️▪️▪️▪️▪️▪️▪️▪️▪️▪️▪️▪️ ❇️Use of the gerund Object to + -ing. ❌ : I object to be treated like this. ✅: I object to being treated like this. ▪️▪️▪️▪️▪️▪️▪️▪️▪️▪️▪️▪️ ❇️Using the wrong preposition Repent of, not from. ❌ : He repented from his crime. ✅ : He repented of his crime. 👉Note: Repentance takes for: He fee/5 repentance for his sin. @fluencyinenglish

Journey to Fluency

@fluencyinenglish · Post #7875 · 09.06.2025 г., 15:07

📚 Common Mistake | اشتباه رایج 🔹 Alone vs Lonely @fluencyinenglish 1️⃣ alone = without other people around you 👨‍🏫 کلمه‌ی alone یعنی کسی اطرافمان نیست و تنها هستیم، اما این لزوماً به معنی ناراحتی یا احساس بد نیست. ✅ Example: • I've thought about getting married, but I prefer living alone. من در مورد ازدواج کردن فکر کرده‌ام، اما تنهایی زندگی کردن را ترجیح می‌دهم. 🔸 Notice: "alone" is about the situation (physical), not about your feelings. @fluencyinenglish --- 2️⃣ lonely = feeling sad because you are alone 👨‍🏫 lonely یعنی تنها باشیم و احساس کنیم کسی به ما علاقه ندارد و مورد توجه نیستیم. ✅ Examples: • I didn't know anyone in Boston and felt very lonely. من هیچ کسی را در بوستون نمی‌شناختم و خیلی احساس تنهایی می‌کردم. • Sarah hated the long lonely days in the empty house. سارا از روزهای طولانی و تنهایی در آن خانه‌ی خالی متنفر بود. 🔸 Notice: "lonely" is about the emotion, not just the physical condition. 🔻 Incorrect Sentence: ❌ I was very alone at first but then I made some friends. 🔺 Corrected: ✅ I was very lonely at first but then I made some friends. من در ابتدا خیلی احساس تنهایی می‌کردم، اما بعد چند تا دوست پیدا کردم. 📌 Remember: "Alone" ≠ "Lonely" You can be alone and feel fine — or you can be lonely even in a crowd. 🎯 یادگیری دقیق تفاوت‌ها باعث می‌شه انگلیسی‌ات طبیعی‌تر باشه. @fluencyinenglish #EnglishTips#Vocabulary#CommonMistakes#WritingandGrammar#fluencyinenglish

Journey to Fluency

@fluencyinenglish · Post #7908 · 17.02.2026 г., 19:57

Difference Between “drop out” and “be dropped out” Many people make this mistake: ❌ I was dropped out This sentence is grammatically incorrect. The correct structure is: ✅ I dropped out. Meaning: I voluntarily left or withdrew from school/university. Why “was dropped out” is wrong “Drop out” is an intransitive verb. It does not take an object, so it cannot be used in the passive voice. ❌ You cannot say: I was dropped out of university. Because dropping out is something you do yourself. Correct Usage If it was your decision: I dropped out of university. If it wasn’t your decision: Use other verbs to express that: I was expelled from university. I was forced to leave university. @fluencyinenglish #EnglishGrammar#GrammarTips#DropOut#PassiveVoice#IntransitiveVerbs#IELTSGrammar#CommonMistakes#LearnEnglish#TEFL