Один из самых удобных способов записать данные это использование готовых форматов, такие как 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
🇷🇺 On June 10, 2023, a state reception on the occasion of the national holiday - #RussiaDay was held at the Russian Embassy in Malta. Among the guests were compatriots, public figures, entrepreneurs, representatives of education, science and culture.
❗️Russian Ambassador to Malta H.E. Andrey Lopukhov addressed the audience with a welcoming speech, emphasizing the importance of this annual event for the consolidation of the Russian community living in Malta. He also noted that Russia is ready to cooperate with those countries that declare their readiness and willingness to cooperate with us.
📷The photo exhibitions "Achievements of Russia" and "Beauty of Russia" were presented to the audience.
🎵The evening was accompanied by live performances of Russian and Maltese musical compositions. The guests were offered dishes of the traditional Russian cuisine.
The reception was held in a warm and friendly atmosphere.
#RussiaDay2023🇷🇺🇷🇺🇷🇺
🇷🇺 On June 15, 2023, the state reception on the occasion of #RussiaDay was held at the Hotel Mulia Senayan in Jakarta. The celebration was attended by esteemed representatives of the Indonesian government, socio-political, business, academic, creative and religious circles, compatriots, journalists, as well as foreign diplomats.
🎙️Welcoming remarks at the function were delivered by H.E. Mrs Lyudmila Vorobyeva, Ambassador of the Russian Federation to the Republic of Indonesia (read in full), H.E. Mr Evgeny Zagaynov, Ambassador of the Russian Federation to ASEAN, and H.E. Mr Budi Gunadi Sadikin, Minister of Health of the Republic of Indonesia, as the Guest of Honour.
💬Ambassador Lyudmila Vorobieva: It is a pleasure to welcome you all at the reception on the occasion of the Day of Russia. We are celebrating the unity and the strength of our country which is one of the main players on the global arena and whose people is looking into the future with confidence and pride.
Russia and Indonesia have a long history of successful cooperation traditionally based on principles of friendship, mutual understanding and trustworthy dialogue.
🎵 The cultural programme of the event included works of great Russian composers P.I.Tchaikovsky and S.V.Rachmaninov played by graduates of Russian musical universities, as well as pieces by local dance ensembles and musicians. The Indonesian song "Rayuan Pulau Kelapa" performed in two languages — Russian and Indonesian — took a special place in the programme of the evening.
📸 The Embassy also organised an art exhibition of Russian landscapes which allowed guests to experience the authentic character of our Motherland and to enjoy picturesque views from various parts of Russia.
#RussiaDay
#RussiaDay2023
🇷🇺 On June 12, we celebrate #RussiaDay across the entire country and abroad.
It reflects #Russia’s contemporary development, as well as its centuries-old path, endeavours & achievements.
🇷🇺 Happy Russia Day!
#RussiaDay#RussiaDay2023#Russia1Love#WeAreRussia