Один из самых удобных способов записать данные это использование готовых форматов, такие как 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
🪐 Astronomers have pinpointed the exoplanet LP 890-9 c, located about 105 light-years away in the constellation Eridanus, as one of the most promising places for life outside our solar system. This rocky world orbits within its star’s habitable zone—the region where temperatures could allow liquid water to persist, making it a key target in the search for planets that might support life as we know it. ✨
#exoplanets⚡#habitability⚡#astrobiology⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
👉more Channels
🪐 Just 12 light-years away, the red dwarf star Teegarden’s Star hosts two Earth-sized exoplanets, Teegarden’s Star b and c, both located in the star’s habitable zone. This zone is the area around a star where temperatures could allow liquid water to exist—a key ingredient for life as we know it—making these planets some of the most intriguing nearby candidates in the search for life beyond our solar system. ✨
#exoplanets⚡#habitablezone⚡#astrobiology⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
🪐 Astronomers have found hints that life could exist in the clouds of Venus, where temperatures and pressures about 50 kilometers above the surface become surprisingly mild—unlike the planet's scorching surface below. While Venus’s atmosphere is highly acidic, scientists have detected unusual patterns of sulfur compounds that might be explained by unknown chemical processes or possibly even tiny airborne microbes adapted to these harsh conditions. ✨
#Venus⚡#astrobiology⚡#atmosphere⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
🪐 Deep beneath the icy surface of Jupiter’s moon Callisto, scientists believe there is a salty ocean more than 100 kilometers thick. The presence of this hidden ocean, combined with a surface rich in organic compounds (carbon-based molecules essential for life), makes Callisto another intriguing candidate for life beyond Earth. ✨
#Callisto⚡#astrobiology⚡#oceans⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
🪐 Scientists studying Saturn’s moon Rhea have spotted hints of a thin atmosphere made of oxygen and carbon dioxide—an extremely rare find among icy moons. While this atmosphere is very tenuous (about 5 trillion times thinner than Earth's), its presence sparks interest in how chemical processes on Rhea’s surface, possibly driven by sunlight or charged particles from Saturn’s rings, might offer clues about where life’s ingredients could gather even in far-off, frozen places. ✨
#Rhea⚡#astrobiology⚡#moons⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
👉more Channels
🪐 Within our solar system, scientists have discovered that the subsurface ocean of Neptune’s moon, Triton, could provide the right conditions for life despite its bitterly cold surface. Tidal forces, or gravitational stretching from Neptune, may keep this hidden ocean liquid beneath Triton’s icy shell, making it a fascinating target in the ongoing search for places where life could exist beyond Earth. ✨
#Triton⚡#ocean⚡#astrobiology⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
🪐 One of the most intriguing places where life could exist is inside the clouds of Jupiter, the largest planet in our solar system. While the surface and deep atmosphere are far too hostile, certain layers of Jupiter's thick cloud tops reach mild temperatures and pressures similar to those found on Earth’s surface, leading scientists to consider if floating microbes—like those in Earth’s high atmosphere—could possibly survive in this extreme environment. ✨
#Jupiter⚡#astrobiology⚡#cloudlife⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
👉more Channels
🪐 Jupiter’s moon Europa hides a vast, salty ocean beneath its icy surface, making it one of the best places to look for life beyond Earth. This subsurface ocean, kept liquid by tidal forces (the push and pull from Jupiter’s gravity), may contain more water than all of Earth’s oceans combined, providing a stable environment where life could potentially thrive deep below the ice. ✨
#Europa⚡#ocean⚡#astrobiology⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
🪐 Saturn’s tiny moon Enceladus harbors a global ocean beneath its icy crust, and scientists have detected plumes of salty water and organic molecules—building blocks of life—eruption from cracks near its south pole. These discoveries suggest that Enceladus may offer the right conditions for simple life to exist, hidden far below the frozen surface. ✨
#Enceladus⚡#astrobiology⚡#ocean⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
🪐 Scientists have discovered that Mars’ Jezero Crater once held an ancient lake, where water persisted long enough to form river deltas and deposit clay minerals—materials that can preserve signs of life for billions of years. The Perseverance rover is now exploring this region, searching for tiny fossilized microbes that may have thrived in Mars' watery past. ✨
#Mars⚡#Perseverance⚡#astrobiology⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
🪐 Scientists have found that the atmosphere of Venus contains traces of phosphine, a gas that on Earth is mainly produced by living organisms, sparking renewed interest in whether microbial life could exist in Venus’s thick clouds. The surface of Venus is scorching hot and uninhabitable, but its upper cloud layers offer milder temperatures and unique chemistry, making this hostile world an unexpected target in the search for possible life beyond Earth. ✨
#Venus⚡#biosignatures⚡#astrobiology⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
👉more Channels
🪐 Deep below the surface of the dwarf planet Ceres, scientists have found evidence for salty liquid water—brines—existing within its crust. Observations from NASA’s Dawn spacecraft show that Ceres’s bright spots are deposits left behind by recent briny water seeping up, hinting that this small world might still hold environments where simple life could survive, far from the warmth of the Sun. ✨
#Ceres⚡#brines⚡#astrobiology⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
👉more Channels