@googlefactss · Post #40777 · 12.03.2026 г., 07:01
A group of jellyfish is called a bloom, swarm, or smack. @googlefactss#nowyouknow
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
Пребарај: #nowyouknow
@googlefactss · Post #40777 · 12.03.2026 г., 07:01
A group of jellyfish is called a bloom, swarm, or smack. @googlefactss#nowyouknow
Hashtags
@googlefactss · Post #40758 · 07.03.2026 г., 15:04
Jellyfish move in essentially two ways. They take water in their bell and then squirt it out behind them, which creates a jet of water that moves them forward. They also drift on water currents. @googlefactss#nowyouknow
Hashtags
@googlefactss · Post #40710 · 27.02.2026 г., 07:04
Horseshoe crabs are not crabs at all. They are not even crustaceans. Instead, they have their own separate class named Merostomata. They have hardly changed since the age of the dinosaurs, and their closest-living relatives are spiders @googlefactss#nowyouknow
Hashtags
@googlefactss · Post #40525 · 11.01.2026 г., 19:02
Blind people smile even though they have never seen anybody else smile. Facial expressions like smiling are largely innate and biological, not just learned through visual imitation and not learned at all. @googlefactss#nowyouknow
Hashtags
@googlefactss · Post #39979 · 30.10.2025 г., 08:02
Stan is an ancient Persian word meaning “land” or “nation,” and Kazakh means “wanderer,” “adventurer,” or “outlaw.” Therefore, the name Kazakhstan translates as “Land of the Wanderers. @googlefactss#nowyouknow
Hashtags
@googlefactss · Post #39972 · 29.10.2025 г., 08:48
In terms of absolute size and in proportion to overall body mass, the human penis is longer and thicker than that of any other primate. For instance the average size of the human penis is 8-10 cm when flaccid and 13-15 cm when erect while gorillas, which are the largest primates, have a penis size of approximately 4 cm in length when erect. @googlefactss#nowyouknow
Hashtags
@googlefactss · Post #39942 · 23.10.2025 г., 07:58
The colors of fire hydrants give a reasonably accurate picture as to how much water flow and pressure they can provide @googlefactss#nowyouknow
Hashtags
@googlefactss · Post #39922 · 13.10.2025 г., 12:57
The position dogs assume when they are inviting other pets to play is called a play bow. @googlefactss#nowyouknow
Hashtags
@googlefactss · Post #39899 · 03.10.2025 г., 22:04
The historical figure who inspired the Santa Claus legend, Saint Nicholas, was born in Patara, Turkey, in the 3rd century A.D. @googlefactss#nowyouknow
Hashtags
@googlefactss · Post #39888 · 29.09.2025 г., 17:20
Greek philosopher Aristotle (384–322 BC) thought the heart, not the brain, was the center of mental functions, emotions, and intellect. He considered the heart the core of the body's "psychical fire" and the source of its heat, with the brain's main role being to cool the blood. @googlefactss#nowyouknow
Hashtags
@googlefactss · Post #39885 · 29.09.2025 г., 13:02
The al-Qarawiyyin Library in Fez, Morocco is the oldest working library in the world. It was founded in 859 CE by Fatima al-Fihriya. @googlefactss#nowyouknow
Hashtags
@googlefactss · Post #40641 · 09.02.2026 г., 15:02
Napoleon I banned fashion dolls because he was nervous they could be used to send secret messages. [Read more] @googlefactss#nowyouknow#history
Hashtags