Один из самых удобных способов записать данные это использование готовых форматов, такие как 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
Tuscany, #Italy
Tuscany is the birthplace of the Italian language. Tuscany was a very important cultural and historical center. She had a significant impact on the social and artistic development of Europe and the whole world.
Burano Island, Venice, #Italy
In order not to get lost in the thick fog and find their way home, the residents of Burano painted their houses in very bright colors. Later, such a need disappeared, but the tradition remained. Today, the coloring of houses is regulated by the municipality. Residents can only paint their houses according to the permitted palette.
Milan Cathedral, #Italy
The main Cathedral of Milan (Duomo di Milano) - The Duomo or Cathedral of the Nativity of the Virgin Mary was built for more than 500 years. Construction began in the 14th century and ended in the early 19th century, with the last door of the temple being installed in 1965.
Sardinia, #Italy🇮🇹
Sardinia has a law prohibiting the export of sand and pebbles from the island.
The most traditional dish in Sardinia is Fregola pasta, made from a paste of unusual shape, served with tomato sauce and an abundance of seafood.
One of the favorite delicacies of Sardinians is sea urchins.
Loreto Island, #Italy
Due to the small number of documents that have survived to this day, little is known about the island's past, until 1910, when Cavalier Vincenzo Ricchieri decided to build a neo-Gothic castle here, which today is a private residence.
Dolomites, #Italy
The Dolomites are often called the Prealps, the beginning of the Alps, although these mountains are not very high. There are 18 peaks with a height of more than 3 thousand meters, and in some places there is even snow in summer.
Umbria, #Italy🇮🇹
From the windows of Castello-Di-Rocko Castle-now a hotel with 36 Syuts, a restaurant and an underground spa-and residences views of neat rows of vineyards and cypress alleys.
For almost 30 years, the Bolz family managed to return the thousand -year castle to life, but there are still many work ahead of their own admission. The immediate plans are to open a second restaurant in the territory, but this is only another, not the last step.
「🌺」#italy
The sightseeing did not end there. For the next couple of days we kept exploring Florence. Thanks to our wonderful professor almost everyday we had field trip to some gallery or museum with guides who told us about the history of Florence and more. For the rest of the time we explored on our own, went to popular affogato place, to bookstore with cinema inside and golden bridge where we watched sunset (it was the best place imo).
The art galleries and museums in Florence are PACKED! Overall we went to Villa la Pietra (which is the villa owned by NYU💅), Pitti Palace and Boboli Gardens, The Uffizi Gallery, Gucci Museum, and last but not least Ferragamo Museum.
The one I enjoyed the most was Pitti Palace and Boboli Gardens AND Ferragamo Museum. More about them in upcoming posts...
All those times the weather was rainy and sometimes sunny, it changes so fast.
Sometimes you can catch musicians performing in the middle of the streets just like we did. It is so fascinating honestly.
~🍋~
↬@jastm1🌊
「🌺」#italy
Firenze – First Couple of Days 🇮🇹
We arrived on campus and were immediately blown away by its beauty and grandeur. It wasn’t just beautiful it was absolutely massive. Everywhere we looked, there were tall trees and old sculptures, all perfectly blended into the landscape.
We had a mini tour of the campus followed by a quick walk through the city center. I was honestly too stunned to speak, everything was just so incredible 🥲.
Then came the food: we had what might have been the best pizza ever. It was seriously THAT good. And of course, we had gelato at local spot. Little did we know … it was not even the best gelato in town!
Exhausted but happy, we called it a night. Wait for next part. ✨
~🍋~
↬@jastm1🌊
「🌺」#italy
We also tried affogato at one of the oldest places in Florence! Under the rain it was really nice to have hot espresso with vanilla ice cream🥰. I really want to come back here with my family, I am kind of feeling guilty for experiencing all of this by myself only 😭🙏.
~🍋~
↬@jastm1🌊
「🌺」#italy
It is a bit hard to find halal food cause sometimes they even add alcohol in food with only veggies so you need to be careful. Guess we are vegetarians in Italy 😄🤩
Tomato,basil and cheese combo is SOO good tho!
~🍋~
↬@jastm1🌊
「🌺」#italy
Architecture in Italy is crazy just like in every other city in Europe!
You can just take a random picture and it would be so aesthetic. The only thing is that we were warned to be aware of our bags and overall to stay alert and walk in groups🥲🚨
~🍋~
↬@jastm1🌊