Один из самых удобных способов записать данные это использование готовых форматов, такие как JSON или YAML.
Из плюсов такого подхода стоит отметить вот что:
🔸 готовый, повсеместно используемый и поддерживаемый формат
🔸 простой и понятный файл, удобочитаемый для человека
🔸 можно легко редактировать в любом текстовом редакторе без специальных программ и библиотек
Но есть и минусы
🔹 затраты времени при записи файла (кодирование данных в нужный формат строки)
🔹 затраты времени при чтении файла (декодирование данных в Python объекты)
🔹 размер файла увеличивается из-за разметки данных (скобки, запятые, переносы, отступы...)
🔹 перед записью все данные должны быть помещены в память в полном объёме (не всегда)
🔹 при чтении необходимо считать весь файл в память и только потом декодировать данные
Если нужно писать немного данных в несколько файлов, то затраты по времени не ощутимы. Обычно это файлы конфига или какие-либо метаданные. Это отличный вариант под такие задачи.
Есть и другой поход к записи файлов - это бинарные файлы. Используется, когда данных достаточно много и никто их не собирается читать глазками😳.
🔸 очень быстрая запись
🔸 чтение значительно быстрей чем JSON, YAML итд
🔸 размер файла значительно меньше, так как нет разметки
🔸 можно записывать данные по мере поступления не загружая всё в память
🔸 можно извлечь любую часть данных независимо
Из минусов
🔹 нужно определить свой формат записи данных (если не используете готовую спецификацию определённого формата)
🔹 не получится открыть файл и визуально понять что там записано, а для чтения файла потребуется знать его спецификацию.
🔹 не так-то просто создать такой файл без специальной библиотеки
В таком виде удобно записывать большой массив любых однородных данных. Например, мониторинг валютной биржи или кэшированная анимация 3D геометрии.
(Это не означает что нельзя записать данные разного типа, просто это будет не так удобно)
Представьте себе JPG-картинку. По сути это немного мета-информации и большой массив пикселей. Тоже самое со звуком или видео файлом. Поэтому, если вы попробуете открыть картинку в текстовом редакторе вы увидите что-то вроде такого
f15d cd29 a564 4578 ...
09e2 9bc4 a696 1253 ...
84e9 4de1 3b23 c24a ...
2534 5161 28e0 709d ...
...
Это и есть записанные байтики. И для их чтения требуется определённый софт который знает что с ними делать. Под каждый тип файла.
К чему это я? Читайте в следующем посте...
#tricks#basic
🪐 The giant planet WASP-96b, discovered about 1,150 light-years from Earth, made headlines when the James Webb Space Telescope detected a clear signature of water vapor in its scorching atmosphere. Unlike planets in our solar system, WASP-96b has no clouds and its skies allow starlight to pass straight through, giving scientists an unusually direct view of a giant planet's steamy, alien air. ✨
#giantplanets⚡#exoplanets⚡#atmosphere⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
🪐 The giant exoplanet HD 209458b, located about 150 light-years from Earth in the constellation Pegasus, is known as "Osiris" and was the first planet beyond our solar system found to have an atmosphere. As it orbits extremely close to its star, its atmosphere is heated and blown away by stellar radiation, creating a long tail of escaping gas much like a comet streaking through space. ✨
#giantplanets⚡#exoplanets⚡#atmosphere⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
🪐 Exoplanet HAT-P-7b, a giant planet about 1,040 light-years away in the constellation Cygnus, experiences wild weather that causes its thick clouds to constantly switch sides. Powerful winds, driven by the planet’s close orbit to its star, move clouds of vaporized minerals from one hemisphere to the other—a phenomenon never seen anywhere else in the universe. ✨
#giantplanets⚡#exoplanets⚡#weather⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
🪐 The giant planet HD 189733b, located about 64 light-years away in the constellation Vulpecula, is famous for having blue clouds made of molten glass that whip through its atmosphere at wind speeds over 7,000 kilometers per hour. Unlike Earth's gentle blue sky, the blue color of HD 189733b comes from silicate particles that scatter blue light, creating a world where glass rain falls sideways in scorching, stormy gales. ✨
#exoplanets⚡#giantplanets⚡#atmospheres⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
👉more Channels
🪐 Some of the most mysterious worlds in our galaxy are rogue planets like CFBDSIR J214947.2-040308.9, a giant planet drifting alone in interstellar space without a star to orbit. Detected about 130 light-years from Earth, this lonely world glows with leftover heat from its birth and is studied in infrared light, revealing that even without a sun, planets can wander the dark, silent stretches between stars. ✨
#rogueplanets⚡#interstellar⚡#giantplanets⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
👉more Channels
🪐 Exoplanet WASP-12b, about 1,400 light-years away in the constellation Auriga, is a giant planet so close to its star that its atmosphere is being stripped away, creating a glowing, comet-like tail. This tidal distortion makes WASP-12b egg-shaped rather than round, showing how extreme gravity can reshape giant planets when they orbit near their stars. ✨
#giantplanets⚡#exoplanet⚡#gravity⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
🪐 The giant exoplanet HAT-P-32b, about 950 light-years away in the constellation Andromeda, is so puffed up that it's nearly twice the diameter of Jupiter but only a fraction as dense—almost like a balloon made of hot gas. Its incredibly low density means a bathtub big enough for HAT-P-32b would float it, revealing how giant planets can take on bizarre, bloated forms far beyond the familiar giants of our own solar system. ✨
#exoplanets⚡#giantplanets⚡#hatp32b⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
👉more Channels
🪐 The enormous exoplanet HD 100546 b, located about 320 light-years away in the constellation Musca, is one of the youngest giant planets ever observed—less than 10 million years old. Still surrounded by a swirling disk of gas and dust, this massive world is so new that scientists have caught it in the act of forming, offering a rare glimpse at how giant planets grow while carving out gaps in their birth disks. ✨
#giantplanets⚡#exoplanets⚡#planetformation⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
👉more Channels
🪐 Saturn is so massive and spins so quickly—completing a rotation in just over 10 hours—that its fast spin causes the planet to flatten at the poles and bulge at the equator. This makes Saturn wider across the middle than from top to bottom, giving it a distinct squashed-ball appearance unlike most other planets in the solar system. ✨
#Saturn⚡#giantplanets⚡#rotation⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
👉more Channels
🪐 Jupiter’s Great Red Spot is the largest storm in the solar system—a swirling oval bigger than Earth itself that has raged for at least 350 years. This ancient storm sits high in Jupiter’s atmosphere and its swirling winds reach speeds of over 430 kilometers per hour, offering a glimpse into the extreme weather that can brew on giant planets. ✨
#Jupiter⚡#storms⚡#giantplanets⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
🪐 Neptune’s internal heat keeps this giant planet surprisingly active, releasing more than twice as much energy as it receives from the Sun. This extra energy drives Neptune’s fierce storms and the fastest winds in the solar system, revealing that giant planets can be turbulent worlds even in the freezing dark far from their star. ✨
#Neptune⚡#giantplanets⚡#storms⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
👉more Channels
🪐 The giant planet Neptune, about 17 times heavier than Earth, has the fastest winds in the solar system, reaching speeds over 2,000 kilometers per hour. These icy, supersonic winds zip through Neptune's blue methane clouds, creating enormous, swirling storms that can dwarf our entire planet. ✨
#Neptune⚡#giantplanets⚡#storms⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries