Один из самых удобных способов записать данные это использование готовых форматов, такие как 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
🌎 Scientists believe most of the universe’s mass comes from dark energy, a mysterious force causing space to expand faster over time. Dark energy makes up about 68% of everything in the universe, yet its true nature remains unknown despite decades of study. ✨
#space⚡#cosmology⚡#astronomy
👉subscribe Interesting Planet
👉more Channels
🌎 At the edge of the observable universe, mysterious “dark flow” tugs galaxy clusters in the same direction, hinting at unseen forces or realms beyond our cosmic horizon. This puzzling movement can’t be explained by known gravity alone, sparking debate about what lies outside the visible universe. ✨
#space⚡#universe⚡#cosmology
👉subscribe Interesting Planet
🌎 Multiple theories in modern physics suggest parallel worlds or dimensions could exist, but no direct experimental evidence has ever been found. String theory predicts extra spatial dimensions, and some cosmological models propose the idea of a "multiverse," where many universes exist with different physical laws. As of 2024, all searches for measurable proof—such as deviations in gravity or missing energy—have reported no confirmed signs of parallel worlds. ✨
#physics⚡#multiverse⚡#cosmology
👉subscribe Interesting Planet
👉more Channels
🌎 In physics, the concept of a "multiverse" proposes that our universe could be just one of many coexisting universes, each with different physical laws. This idea arises in cosmic inflation theory, where rapid early expansion could have created countless separate "bubble universes." The multiverse hypothesis is explored by leading scientists but remains unproven, and no direct evidence has yet been observed. ✨
#multiverse⚡#cosmology⚡#physics
👉subscribe Interesting Planet
👉more Channels
🌎 The concept of a "mirror universe" is explored in cosmology, referring to the idea of a universe with particles and forces that mirror our own but interact only through gravity. While no evidence currently supports their existence, theories suggest mirror matter could help explain mysteries like dark matter. Researchers at Oak Ridge National Laboratory have tested for potential interactions but found no signs so far. ✨
#parallelworlds⚡#physics⚡#cosmology
👉subscribe Interesting Planet
👉more Channels
🌎 The mysterious "cold spot" in the cosmic microwave background is a vast region of space cooler than its surroundings. Some scientists think it may be the result of a gigantic supervoid—an unusually empty part of the universe spanning nearly 1.8 billion light-years across. This cold spot is one of the largest anomalies detected in the afterglow of the Big Bang, challenging current models of cosmic structure. ✨
#universe⚡#cosmology⚡#supervoid
👉subscribe Interesting Planet
👉more Channels
🪐 The cosmic microwave background contains a hidden signature called the "Sachs-Wolfe effect," where variations in temperature are linked to the gravitational pull of massive structures like galaxy clusters. This effect, first detected in the 1990s using data from the COBE and WMAP satellites, shows how even the oldest light in the universe was influenced by the invisible gravity of objects such as the Coma Cluster and the Great Attractor, providing a glimpse into how matter was distributed across the cosmos more than 13 billion years ago. ✨
#cosmology⚡#gravity⚡#universe⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#cosmos⚡#space
👉subscribe Universe Mysteries
👉more Channels
🪐 The ultimate fate of the universe may come in a dramatic event known as the "Big Rip," where the repulsive force of dark energy—an unseen force causing galaxies like Sombrero Galaxy (Messier 104) to speed away from each other—could grow so strong that it eventually tears apart galaxy clusters, stars, planets, and even atoms themselves. If the Big Rip happens, it would be the final act in cosmic history, ending everything from the largest galaxy clusters down to the smallest subatomic particles in a relentless expansion. ✨
#universe⚡#darkenergy⚡#cosmology⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#cosmos⚡#space
👉subscribe Universe Mysteries
👉more Channels
🪐 The ultimate fate of the universe is still a mystery, but scientists study clues from galaxies like Messier 87 and the emptying regions between them to predict what lies ahead. Over trillions of years, after all the stars burn out—including giants like Betelgeuse—and black holes such as Sagittarius A* slowly evaporate, space will stretch into a cold, dark expanse with only faint traces of ancient matter drifting across an ever-growing emptiness. ✨
#universe⚡#fate⚡#cosmology⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#cosmos⚡#space
👉subscribe Universe Mysteries
👉more Channels
🪐 Scientists believe the universe's end could unfold in several dramatic ways, including the "Big Rip," where dark energy tears galaxies, stars, and even atoms apart. In contrast, the "Big Crunch" scenario imagines gravity eventually halting expansion and pulling everything—including galaxies like the Milky Way—back together in a catastrophic collapse. Another possibility is the "Big Freeze," where the expansion continues until the last stars, like our Sun, burn out and the universe grows eternally cold and dark, filled only with faint remnants like white dwarfs and black holes. ✨
#universe⚡#fate⚡#cosmology⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#cosmos⚡#space
👉subscribe Universe Mysteries
🪐 The end of the universe is a cosmic puzzle with several real scenarios proposed by scientists, each based on clues from galaxies like Messier 87 and ancient light observed by telescopes. One idea is the "Big Bounce," where the universe’s expansion might someday reverse due to gravity, causing everything—including stars such as Betelgeuse and black holes like Sagittarius A*—to collapse back into an ultra-dense state, possibly leading to another cosmic cycle. Unlike the "Big Freeze" or "Big Rip," the "Big Bounce" is still debated, but it shows how the fate of the universe could depend on the balance between gravity and mysterious forces such as dark energy. ✨
#universe⚡#cosmology⚡#expansion⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#cosmos⚡#space
👉subscribe Universe Mysteries
👉more Channels
🪐 The cosmic microwave background is not just a faint afterglow—embedded within it are tiny, swirling patterns called "polarization anomalies," first mapped in detail by the Planck satellite. These twists in the microwave light tell scientists how matter and light interacted in the early universe, revealing clues about the first few moments after the Big Bang and hinting at processes like cosmic inflation—an explosive expansion that happened in fractions of a second. ✨
#cosmology⚡#universe⚡#bigbang⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#cosmos⚡#space
👉subscribe Universe Mysteries
👉more Channels