@sbwalls · Post #39741 · 05.08.2024 г., 10:57
#Rings
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
Пребарај: #rings
@sbwalls · Post #39741 · 05.08.2024 г., 10:57
#Rings
Hashtags
@cosmomyst · Post #12 · 29.07.2025 г., 18:51
🪐 Hidden deep inside Saturn’s rings, astronomers have discovered tiny moonlets like Daphnis that carve out delicate waves and gaps as they orbit, sculpting the rings’ sharp edges. These miniature moons cause astonishing ripples and wakes, their gravitational dance leaving patterns that shift with every pass. ✨ #Saturn⚡#moonlets⚡#rings 👉subscribe Universe Mysteries
@cosmomyst · Post #749 · 22.04.2026 г., 22:21
🪐 The galaxy Arp 147 shows off one of the universe’s strangest shapes—a bright blue ring of young stars wrapped around a reddish core, formed after a dramatic collision with another galaxy. This kind of "ring galaxy" is extremely rare, created when one galaxy punches through another, sending waves through the gas and sparking new stars to ignite in a perfect circle, making Arp 147 a cosmic example of how galactic crashes can sculpt extraordinary structures. ✨ #galaxies⚡#collisions⚡#rings⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space 👉subscribe Universe Mysteries 👉more Channels
@cosmomyst · Post #501 · 16.11.2025 г., 12:21
🪐 The galaxy NGC 922, located about 157 million light-years away in the constellation Fornax, sports a dramatic ring-shaped structure that formed after it collided with a smaller galaxy. This "collisional ring galaxy" features a bright, blue ring of new stars encircling its core, revealing the powerful effects of galactic crashes and creating a cosmic shape rarely found in the universe. ✨ #galaxies⚡#rings⚡#collisions⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space 👉subscribe Universe Mysteries 👉more Channels
@cosmomyst · Post #687 · 18.02.2026 г., 12:21
🪐 The galaxy Hoag's Object, located about 600 million light-years away in the constellation Serpens, is a stunning example of a ring galaxy—a nearly perfect circle of bright blue stars surrounding a yellow core. This puzzling shape is believed to have formed when another galaxy passed through Hoag's Object, disrupting its stars and creating the iconic cosmic ring, a form almost never seen among the billions of known galaxies. ✨ #galaxies⚡#serpens⚡#rings⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space 👉subscribe Universe Mysteries 👉more Channels
@cosmomyst · Post #603 · 05.01.2026 г., 12:21
🪐 Saturn’s rings are made mostly of icy particles ranging from the size of grains of sand to mountains, but what’s remarkable is that these rings are incredibly thin—often only about 10 meters thick compared to their width of up to 282,000 kilometers. Despite their vast size, the rings would still fit comfortably within the gap between Earth and the top of our atmosphere if laid flat. ✨ #Saturn⚡#rings⚡#giants⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space 👉subscribe Universe Mysteries 👉more Channels
@cosmomyst · Post #103 · 09.08.2025 г., 00:11
🪐 The giant planet Saturn is the only world in our solar system with rings visible from Earth through even a small telescope, but Saturn is not alone—Jupiter, Uranus, and Neptune each have their own faint and delicate ring systems. Unlike Saturn’s bright icy rings, the rings around Jupiter, Uranus, and Neptune are darker and mostly made of dust, making them nearly invisible except with powerful spacecraft or specialized equipment. ✨ #Saturn⚡#rings⚡#Uranus⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space 👉subscribe Universe Mysteries
@sucai891 · Post #2092 · 07.02.2026 г., 13:17
#戒指#珠宝#购物#rings#shopping
@cosmomyst · Post #236 · 07.09.2025 г., 13:11
🪐 The giant planet Saturn is so light for its size that if you could find a big enough pool of water, it would float—its average density is less than water’s! Saturn's stunning ring system, made mostly of chunks of ice and rock, stretches out more than 280,000 kilometers from the planet, dwarfing the distances between many of its moons. ✨ #Saturn⚡#rings⚡#density⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space 👉subscribe Universe Mysteries