Один из самых удобных способов записать данные это использование готовых форматов, такие как 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
🌎 At the center of some galaxies, astronomers have found supermassive black holes millions to billions of times more massive than our Sun. These powerful objects control the motion of stars and gas near them, and their intense gravity can even launch jets of material thousands of light-years into space. ✨
#astronomy⚡#universe⚡#blackholes
👉subscribe Interesting Planet
👉more Channels
🌎 In 2022, a study using gravitational wave detectors like LIGO examined whether ripples from colliding black holes hinted at hidden dimensions. The research found no evidence for extra spatial dimensions, setting new constraints on theories that propose parallel universes. ✨
#physics⚡#blackholes⚡#dimensions
👉subscribe Interesting Planet
👉more Channels
🪐 In 2021, scientists using the LIGO and Virgo detectors observed gravitational waves from a collision between two massive black holes named GW200129, located over 5 billion light-years away. What made this discovery unusual was the strong "precession" of the black holes’ orbits—a wobble much like a spinning top—which had never been clearly seen before, opening a new way to study how spinning black holes merge and ripple through the fabric of space. ✨
#gravitationalwaves⚡#blackholes⚡#space-time ⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
👉more Channels
🪐 In 2016, scientists using the Laser Interferometer Gravitational-Wave Observatory (LIGO) made history by detecting gravitational waves from the collision of two black holes over a billion light-years away. Gravitational waves are actual ripples in the fabric of space itself, created when massive objects like black holes or neutron stars crash together, letting astronomers "hear" cosmic events that were invisible before. ✨
#blackholes⚡#gravitationalwaves⚡#space-time ⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
👉more Channels
🪐 The distant future of the universe could see galaxies like Messier 87 and the Milky Way fading away, as stars slowly burn out and black holes become the last remaining objects. Over trillions of years, even black holes like Sagittarius A* will evaporate through a process called Hawking radiation—an extremely slow release of energy that eventually leaves space empty, silent, and cold. ✨
#universe⚡#fate⚡#blackholes⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#cosmos⚡#space
👉subscribe Universe Mysteries
🪐 The black hole at the heart of the galaxy NGC 1277 is one of the most puzzling known—it makes up over 14% of its galaxy's entire mass, far more than what's typical for supermassive black holes. Researchers are still investigating how NGC 1277’s black hole could have grown so large without swallowing most of the surrounding galaxy, challenging current theories about how black holes and galaxies evolve together. ✨
#blackholes⚡#galaxies⚡#mysteries⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
👉more Channels
🪐 The giant elliptical galaxy NGC 4889, located in the Coma Cluster about 308 million light-years away, hosts one of the largest known black holes, weighing more than 21 billion times the mass of our Sun. Even though its black hole is truly enormous, it’s nearly invisible, revealed only by the subtle motion of surrounding stars—demonstrating how black holes can hide in plain sight, influencing entire galaxies without giving off any detectable light themselves. ✨
#blackholes⚡#galaxies⚡#mysteries⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
👉more Channels
🪐 The galaxy NGC 1600, located about 200 million light-years away in the constellation Eridanus, contains a supermassive black hole with a mass over 17 billion times that of our Sun—one of the largest found outside a crowded galaxy cluster. What makes this discovery mysterious is that NGC 1600 is an otherwise ordinary-looking galaxy, leading scientists to question how such a gigantic black hole could grow in a relatively quiet cosmic neighborhood. ✨
#blackholes⚡#galaxies⚡#mysteries⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
👉more Channels
🪐 At the center of the galaxy NGC 1277, astronomers have discovered a supermassive black hole that makes up an astonishing 14% of the galaxy’s total mass—a far greater share than in typical galaxies. Most central black holes are just a tiny fraction of their galaxy’s mass, so NGC 1277’s outsized black hole challenges scientists' understanding of how galaxies and their dark hearts grow together over time. ✨
#blackholes⚡#galaxies⚡#mysteries⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
👉more Channels
🪐 At the center of the galaxy Holmberg 15A, astronomers have discovered one of the largest known black holes, weighing in at around 40 billion times the mass of our Sun. This ultra-massive black hole challenges our understanding of how such giants form and grow, since it's much larger than what scientists expected for a galaxy of its type and size. ✨
#blackholes⚡#galaxies⚡#mysteries⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
🪐 At the core of the spiral galaxy NGC 4395, astronomers have found one of the smallest known supermassive black holes, with a mass only about 10,000 times that of our Sun. Despite its modest size, this black hole still pulls in gas and dust, creating bursts of X-rays and hinting that even tiny supermassive black holes can shape the heart of a galaxy. ✨
#blackholes⚡#galaxies⚡#mysteries⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
🪐 Light speed is so fundamental in the universe that even the most energetic jets from black holes, like those in the galaxy Pictor A, can only approach—but never reach—its ultimate limit of 299,792 kilometers per second. These jets stretch across hundreds of thousands of light-years, yet nothing with mass can break the cosmic speed barrier set by the laws of physics, making the speed of light the universe’s absolute fastest messenger. ✨
#speedoflight⚡#blackholes⚡#galaxies⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
👉more Channels