Один из самых удобных способов записать данные это использование готовых форматов, такие как 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 Trilithon stones at Stonehenge in England each weigh about 25 tons and were transported from over 30 kilometers away. These standing stones date to around 2500 BCE and were arranged in a unique horseshoe pattern that still stands today. ✨
#archaeology⚡#megaliths⚡#history
👉subscribe Interesting Planet
👉more Channels
🌎 Towering over the Peruvian desert, the megalithic complex of Sacsayhuamán features walls made from stone blocks weighing up to 200 tons each. These blocks fit so precisely that even a piece of paper cannot slide between them. ✨
#archaeology⚡#history⚡#megaliths
👉subscribe Interesting Planet
👉more Channels
🌎 Rising above the Jordanian desert, the prehistoric megaliths known as “desert kites” are vast stone structures with funnel-shaped walls stretching for hundreds of meters. Archaeologists have identified more than 6,000 desert kites across the Middle East, mostly built between 7000 BCE and 2000 BCE, likely used to trap wild animals. ✨
#archaeology⚡#megaliths⚡#history
👉subscribe Interesting Planet
👉more Channels
🌎 Looming over the English Channel, the Carnac stones on Guernsey form a megalithic passage grave known as Le Déhus. Built around 3500 BCE, it features a massive stone chamber and carved capstones. The longest stone weighs nearly 10 tons and the site is aligned to the sunrise at midsummer. ✨
#archaeology⚡#megaliths⚡#history
👉subscribe Interesting Planet
👉more Channels
🌎 Hidden in the forests of western Russia, the megalithic dolmens of the Caucasus feature massive stone chambers built from precisely carved granite slabs. Some of these structures date back over 5,000 years and weigh more than 15 tons each, puzzling archaeologists with their construction methods and unknown cultural origins. ✨
#megaliths⚡#archaeology⚡#history
👉subscribe Interesting Planet
👉more Channels
🌎 Stonehenge in England features massive upright stones called sarsens, each weighing up to 25 tons. Built around 2500 BCE, the monument’s purpose is still debated, but recent studies found the stones were transported from over 25 kilometers away on wooden sledges and rollers. ✨
#archaeology⚡#megaliths⚡#history
👉subscribe Interesting Planet
👉more Channels
🌎 The megalithic site of Carnac in Brittany, France, contains over 3,000 standing stones arranged in rows stretching more than 4 kilometers. Erected between 5000 and 3300 BCE, these granite monoliths are among the world’s largest collections of ancient stone alignments. ✨
#archaeology⚡#megaliths⚡#history
👉subscribe Interesting Planet
👉more Channels
🌎 In southern England, the ancient monument of Silbury Hill rises 40 meters and was built over 4,000 years ago using chalk and earth. Archaeologists have never found burials, temples, or inscriptions inside, leaving its purpose mysterious. Silbury Hill is the largest man-made prehistoric mound in Europe. ✨
#archaeology⚡#mystery⚡#megaliths
👉subscribe Interesting Planet
👉more Channels
🌎 The “Plain of Jars” in Laos is scattered with thousands of massive stone jars, some weighing over 10 tons. Archaeologists date them to the Iron Age, around 500 BCE to 500 CE, but their purpose—possibly for funerary or storage rites—remains uncertain. Over 90 jar sites have been documented across the region. ✨
#archaeology⚡#megaliths⚡#mystery
👉subscribe Interesting Planet
👉more Channels
🌎 The Baalbek Trilithon in Lebanon features three enormous stone blocks, each weighing around 800 tons, forming the base of the Roman Temple of Jupiter. These stones are among the heaviest ever used in ancient construction, and were quarried and moved more than 800 meters from their original location. ✨
#archaeology⚡#megaliths⚡#engineering
👉subscribe Interesting Planet
👉more Channels
🌎 Towering in the remote Pacific, the moai statues of Easter Island were carved from volcanic rock between 1400–1650 CE. The heaviest moai weighs around 82 tons, showcasing the islanders’ exceptional engineering with limited technology. ✨
#megaliths⚡#archaeology⚡#engineering
👉subscribe Interesting Planet
👉more Channels
🌎 Rising from the Lebanese landscape, the megalithic stones of Baalbek include the Stone of the Pregnant Woman—one of the world’s largest quarried stones at over 1,000 tons. Ancient builders moved and stacked these limestone giants with such precision that modern engineers still debate the techniques used. ✨
#archaeology⚡#megaliths⚡#engineering
👉subscribe Interesting Planet