Один из самых удобных способов записать данные это использование готовых форматов, такие как 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 edge of the observable universe, astronomers find “quasars”—super-bright objects powered by black holes. Quasars emit energy equal to trillions of suns and help reveal the early universe’s structure. ✨
#space⚡#quasars⚡#astronomy
👉subscribe Interesting Planet
👉more Channels
🪐 The quasar J0313–1806 is one of the most distant known objects in the universe, shining from over 13 billion light-years away. Quasars are the bright centers of young galaxies powered by supermassive black holes, and J0313–1806’s powerful light reveals it existed just 670 million years after the Big Bang, allowing astronomers to study the early universe’s first giant black holes and galaxies. ✨
#space⚡#distances⚡#quasars⚡#universe⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#cosmos
👉subscribe Universe Mysteries
🪐 Deep in the heart of galaxy 4C +37.11, astronomers have found a pair of supermassive black holes separated by just 24 light-years, each powering its own quasar—an extremely bright object fueled by matter falling into a black hole. Quasars outshine entire galaxies, and the unique twin system in 4C +37.11 gives scientists a rare look at how two powerful quasars can exist side by side, lighting up their galaxy with intense energy streams. ✨
#quasars⚡#pulsars⚡#galaxies⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
👉more Channels
🪐 The quasar 3C 273, located in the constellation Virgo about 2.4 billion light-years from Earth, was the first quasar ever identified and remains one of the brightest in the sky. A quasar is a super-energetic beacon powered by a supermassive black hole devouring matter, shining so brightly that it can outshine entire galaxies, and 3C 273 helped scientists understand just how extreme and distant these cosmic engines can be. ✨
#quasars⚡#astronomy⚡#virgo⚡#nasa⚡#galaxy⚡#stars⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
👉more Channels
🪐 The quasar TON 618, found more than 10 billion light-years away in the constellation Canes Venatici, hosts one of the largest known black holes with a mass over 60 billion times that of our Sun. Quasars are incredibly bright objects powered by material falling into supermassive black holes, while pulsars—like the famous Vela Pulsar in our galaxy—are ultra-dense, spinning neutron stars that send out regular beams of radio waves, acting like cosmic lighthouses for astronomers. ✨
#quasars⚡#pulsars⚡#blackholes⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
👉more Channels
🪐 In the heart of the galaxy IC 310, astronomers have observed a quasar that suddenly switches between a quiet state and violent outbursts, blasting powerful jets of particles close to the speed of light. Quasars are some of the brightest objects in the universe, powered by supermassive black holes devouring matter, and IC 310’s unpredictable behavior shows how even these cosmic engines can rapidly transform, lighting up entire galaxies in moments. ✨
#quasars⚡#jets⚡#galaxies⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
👉more Channels
🪐 The quasar PKS 0637-752, located about 7.8 billion light-years from Earth, shoots out a jet of particles more than 2 million light-years long—much farther than the diameter of our Milky Way. Quasars are the brilliant, active centers of young galaxies powered by material falling into supermassive black holes, and these enormous jets show how energy can be launched across intergalactic space by the universe’s most powerful engines. ✨
#quasars⚡#jets⚡#galaxies⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
👉more Channels
🪐 In 1967, astronomers discovered the first pulsar, now known as PSR B1919+21, a rapidly spinning neutron star that sends out regular radio pulses like a cosmic lighthouse. Unlike pulsars, quasars such as 3C 273 are the blazing hearts of distant galaxies, powered by supermassive black holes devouring matter and shining brighter than whole galaxies—making both objects among the most extreme and mysterious beacons in the universe. ✨
#pulsars⚡#quasars⚡#neutronstars⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
🪐 Deep inside the galaxy 3C 273, astronomers have identified a quasar—a super-bright region powered by a supermassive black hole eating up material, causing it to shine with light brighter than entire galaxies. Meanwhile, the Crab Pulsar in the Crab Nebula is a rapidly spinning neutron star left over from a massive star’s explosion, sending out beams of radio waves and light as it spins—a cosmic lighthouse flashing 30 times a second. ✨
#quasars⚡#pulsars⚡#supernova⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
🪐 Deep in the constellation Virgo, the double pulsar system PSR J0737−3039A/B is made of two neutron stars—tiny, ultra-dense remnants of massive stars—that both emit regular radio pulses as they orbit each other every 2.4 hours. This unique cosmic pair lets scientists observe the effects of extreme gravity, as one pulsar passes through the other’s powerful wind and their orbit slowly shrinks—confirming predictions from Einstein's theory of general relativity in an environment unlike anywhere else in the universe. ✨
#quasars⚡#pulsars⚡#gravity⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
👉more Channels
🪐 The quasar 3C 454.3 in the constellation Pegasus is a cosmic powerhouse, shining around a trillion times brighter than our Sun due to a supermassive black hole feasting on matter at its core. Meanwhile, the pulsar PSR B1937+21, located about 9,000 light-years away, spins nearly 642 times per second—so fast that it's called a "millisecond pulsar," acting like a fantastically precise cosmic clock as it beams radio waves across the galaxy. ✨
#quasars⚡#pulsars⚡#cosmiclighthouses⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
👉more Channels
🪐 RX J0911+0551 is one of the most distant gravitationally lensed quasars ever found, with its light traveling about 11 billion years to reach us. This quasar—an extremely bright object powered by a supermassive black hole—appears as several split images in the sky because a massive galaxy between us and RX J0911+0551 bends and magnifies its light, acting as a "gravitational lens" and allowing scientists to glimpse extreme distances near the edge of the visible universe. ✨
#quasars⚡#spacelensing⚡#distances⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
👉more Channels