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

Резултати

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

Пребарај: #mv

当前筛选 #mv清除筛选
Pensive|

@PensivePost · Post #5625 · 30.01.2022 г., 13:38

It wasn't intentional! We both knew! You started everything You made me to feel the best in me You made me to understand what true love is You made me to know even affection like this exists You made me to realize all bonds doesn’t need a name You made me to change myself completely… Yeah! It was you behind this beautiful bond but I don’t blame that it’s all your fault now… We’ve been together in many things either be it sad or happiness, victory or failure, emotions or emptiness we stood with each other… You know what!? This is what I have imagined all these years but now I understand that only I needed you in all such situations whereas you never really wanted me by your side. I thought you will feel good when I’m with you; you will need me at the end of the day to share your day; you will search for me when you are not doing well; and lot more that can’t be bundled up in words but you have also made me to realize that you never really wanted me to be by your side… And now all I am doing is to search myself, the true self which have been lost long back in the chaos of loving you blindly… I know what I was, how I was, who I was, before meeting you but now I don’t have even myself with me! It’s all you that I have within me but I don’t blame that it’s all your fault. I know the way you loved me, you cared me, you admired me but all my question is Where’s that person who made me smile without any reason even at odd hours of day? Where’s that person who made me trust them without any need? Where’s that person who made me feel as the most important one? I have expressed my feelings in all possible ways I could and even said you directly but then you ask me again “what should I do?” You know how painful it is to hear such question after letting myself to someone who is close to me than myself… I have understood your situations many times even you knew it pretty well And now I am tired of being the one who understand others and I need to be understood sometimes… I’ve waited for you a lot of times which doesn’t hurt more than you asking “did I ask you to wait?!” what kind of reaction is that to someone who is extremely crazy about you. And I know you don’t need me the way you needed me! Even you know this but you don’t accept it openly. All I did was to love you unconditionally the way you loved me during our starting days… is it this easy for you to change like a totally different person ? Even now I am trying my best to be supportive to you wherein you don’t even have the courtesy to think about my feelings… so when you come to me again after all your issues being sorted out you will not find the one true soul that loved… each time you do this again and again just because I cant leave you. I am losing myself more than the normal and hating myself terribly for not being able to hate you! I do everything for you and react to you only for your behavior, always remember to think a little before you speak… And there are lot more to say but even my words got glued to you and I find it difficult to put it together. This is all my side of the story! if you think the way I portrayed you wrong in here… then tell me your part… at least that may create a reason to talk. #review #mv

Hashtags

~ cosmosy ~ of the world ~

@cosmosy_tg · Post #3606 · 24.04.2026 г., 17:16

⨳ 23.04.26 ⨳ Релиз Lyric Video на песню «Chance ~ 好きだっていう前に ~» Смотреть Lyric Video на YouTube-канале cosmosy: https://youtu.be/w9p37ELUxO4?si=mF4Z6FWXgMATclg8 #mv@cosmosy#cosmosy

Hashtags

~ cosmosy ~ of the world ~

@cosmosy_tg · Post #3282 · 13.04.2026 г., 15:50

⨳ 13.04.26 ⨳ Релиз клипа на песню «Silence ~ body & soul ~»: Смотреть видеоклип на YouTube-канале cosmosy: https://youtu.be/2mUjLyyZOW0?si=Hk5KJZwg_rB5QfpN #mv@cosmosy#cosmosy

Hashtags

~ cosmosy ~ of the world ~

@cosmosy_tg · Post #3251 · 13.04.2026 г., 09:34

⨳ 12.04.26 ⨳ Релиз Lyric Video на песню «Chance ~ 사랑이라 말하기 전에 ~» Смотреть Lyric Video на YouTube-канале cosmosy: https://youtu.be/5hM7UL9bPtI?si=hYdY_59UZCOCgRgR #mv@cosmosy#cosmosy

Hashtags

~ cosmosy ~ of the world ~

@cosmosy_tg · Post #3028 · 31.03.2026 г., 09:36

⨳ 31.03.26 ⨳ Релиз perfomance-видео на песню «Silence ~ body & soul ~»: «Готовы? Мотор 🎬 🔗youtu.be/VOSAeU-qNr4 🫨 Зажигай всем телом и душой! — Релиз клипа: 13 апреля 2026 💿 Заказать альбом „~ of the world ~“ в онлайн-магазинах: linktr.ee/cosmosy » #mv@cosmosy#cosmosy

Hashtags

~ cosmosy ~ of the world ~

@cosmosy_tg · Post #2686 · 24.03.2026 г., 16:32

⨳ 24.03.26 ⨳ Релиз клипа на новый сингл «Chance ~ 사랑이라 말하기 전에 ~» Смотреть клип на YouTube-канале cosmosy «cosmosy — первые, кто открыл любовь за пределами вероятности 🎧Слушать песню „Chance“ 💿Предзаказ второго мини-альбома „~ of the world ~“ » #mv@cosmosy#cosmosy

Hashtags

~ cosmosy ~ of the world ~

@cosmosy_tg · Post #2562 · 20.03.2026 г., 10:04

⨳ 20.03.26 ⨳ Релиз perfomance-видео на песню «Chance ~ 사랑이라 말하기 전에 ~»: «[Official Performance] cosmosy "Chance ~ 사랑이라 말하기 전에 ~" |🖤 Switch ON 🔗https://youtu.be/DiS9MZV2ZuI В полной темноте они нашли свет и переписали все правила любви 📺 Релиз клипа: 26.03.24 🎧 Слушать новую песню: https://cosmosy.sng.to/chance » #mv@cosmosy#cosmosy

Hashtags

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