@QuietWorld · Post #6825 · 30.10.2019 г., 23:30
🔖 Everything that irritates us about others can lead us to an understanding of ourselves. • Carl Jung • Memories, Dreams, Reflections #reflection@quietworld🍃
Hashtags
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
Пребарај: #reflection
@QuietWorld · Post #6825 · 30.10.2019 г., 23:30
🔖 Everything that irritates us about others can lead us to an understanding of ourselves. • Carl Jung • Memories, Dreams, Reflections #reflection@quietworld🍃
Hashtags
@doniyorieltss · Post #1472 · 20.05.2023 г., 01:55
#reflectionon my recent results... For a start, let me just say that I'm more than grateful for another 8.5, not least because it's an improvement over the last one. Yes, I've come so close to securing that elusive Band 9. You know what? I even thought I did. But for me, it's not so much about the score as it is about fun and experience. As much as I may come across as someone chasing after a 9.0, I honestly couldn't care less. Clearly, it is a big milestone and for good reason — very few people understand what it takes to really get there, and I'm fortune enough to be one of them. But I already stopped caring too much about what I now know is nothing but a number — at least I'm trying to do so. In fact, I did not even prepare for this test of mine, which I normally would. I just wanted to see if I was good enough to score a 9.0 on Speaking and 8.0 on Writing; apparently, I am not! In any case, it was all supposed to be fun — something that I did just for the sake of a dopamine hit; a 180-dollar one, in fact. 😅 Seriously, even as I was taking the Speaking test, I could barely suppress the joy that I felt creeping up, because that was the best performance I'd ever put on in my life! There is also a sense of elation at waiting for your results, even more so when you don't know the exact day of the release. And having fun with your friends until 3.00 AM on the occasion of a satisfactory result is a whole nother level! To sum it all up, I would love to achieve what appears to be the greatest feat of IELTS — Band 9.0. However, I shouldn't have to work for it, as it is not priority 'numero uno': the score is supposed to be only a fraction of a lifelong endeavour — at least for me it is! @ieltsulugbeks
Hashtags
@doniyorieltss · Post #1279 · 31.03.2023 г., 18:44
#reflection Lurching from one task to another, I have been finding myself get sucked into the whirlwind of work time and again. That dreadful thing! It's so counterproductive: You want to lead an exemplary lifestyle, and so you work. You think all your troubles will fade away as you take up work. Little do you know, however, more ordeals than ever before are looming on the horizon — starting a new career, unless tapped into, is a surefire way to put a bigger strain on your already deteriorating social life. Instead of lightening your burden, your work just keeps making you all the more miserable, and before you know it, you will be enslaved by what was only supposed to help you. @ieltsulugbeks
Hashtags
@QuietWorld · Post #7633 · 09.10.2020 г., 03:54
Don't read till the end. . . . . . . I hope you are a rebel though 😉 #life#reflection @quietworld🍃
Hashtags
@bestwallpapes · Post #3322 · 22.03.2025 г., 09:25
@Bestwallpapes #Landscape#Reflection
Hashtags
@QuietWorld · Post #6694 · 12.10.2019 г., 14:00
Never feel self-pity, the most destructive emotion there is. How awful to be caught up in the terrible squirrel cage of self. — Millicent Fenwick – #quotes#reflection#selfreminder @quietworld🍃
Hashtags
@FinancialFreedomMagazine · Post #1067 · 13.12.2021 г., 04:39
THIS WEEK... Instead of a weekly #book challenge, we have a #reflection challenge. Basically, the idea is to use this time of year to intentionally discover and align yourself with the work you’re meant to do in 2022. To help you with this, you can download ⬇️ --The 2021-22 Annual Reflection Template-- It's a structured deep dive into who you are, who you might become, and what you want to create for 2022.
Hashtags
@QuietWorld · Post #6688 · 11.10.2019 г., 08:30
Men go abroad to wonder at the heights of mountains, at the huge waves of the sea, at the long courses of the rivers, at the vast compass of the ocean, at the circular motions of the stars; and they pass by themselves.., without wondering. – St. Augustine – #solitude#quotes#reflection @quietworld🍃
Hashtags
@QuietWorld · Post #6654 · 07.10.2019 г., 04:39
You have to start knowing yourself so well that you begin to know other people – a piece of us is in every person we can ever meet. —John D. MacDonald – #quotes#solitude#reflection @quietworld🍃
Hashtags
@Wallpaper_INT · Post #46090 · 10.04.2025 г., 15:30
#Stones#Water#Reflection#8K @Wallpaper_INT
Hashtags
@QuietWorld · Post #6683 · 10.10.2019 г., 09:30
Often we change..; jobs, friends and spouses.. instead of ourselves. — Akbarali H. Jetha – #quotes#reflection#selfdevelopment @quietworld🍃
@QuietWorld · Post #7177 · 30.01.2020 г., 21:57
#words#unusualwords#reflection @quietworld🍃
Hashtags