Один из самых удобных способов записать данные это использование готовых форматов, такие как 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
#Sweden, national parliament election:
S (S&D) is largest in all constituencies but two in Scania where SD (ECR) leads.
SD, M (EPP), KD (EPP), L (RE) are together stronger in the South.
S, C (RE), V (LEFT), MP (G/EFA) together do best in the North and the three largest cities.
➤ europeelects.eu/sweden
🇸🇪#Sweden: The Swedish Coast Guard has seized a Syrian-flagged vessel named Jin Hui, suspected of being part of Russia’s so-called "shadow fleet".
The ship was sailing in Swedish territorial waters south of Trelleborg and had appeared on multiple sanctions lists. Its destination was unclear. Authorities also suspect the vessel may have been operating under a false flag and was reportedly carrying no cargo.
(via Reuters)
#Sweden🇸🇪
The Luleo Archipelago is a group of Swedish islands in the northern part of the Bayer Belonian, located near the city of Luleo and the mouth of the Lule River.
The sea freezes in January and remains frozen until March - April. Ice roads are cleaned by the four populated islands.
📍Sweden🇸🇪
Gorgeous evening view from the Liseberg amusement park in Sweden. 🎢
Liseberg Amusement Park is also a true symbol of love, as it was built in 1923 by merchant Lamberth for his terminally ill wife Lisa. He transformed the former pastureland into a real garden with trees, flowers, and water areas. 🌳🌺😍
After Lisa's death, the park was donated by her husband to the state, and currently, it attracts about 3 million visitors per year, making it one of the most popular entertainment and leisure destinations in Europe.
#Sweden
@voyage
🇸🇪#Sweden - 🇷🇺#Russia: The Swedish Coast Guard, together with the police, has boarded another vessel suspected of operating under a false flag off the coast of Trelleborg.
The oil tanker, named "Sea Owl I", is believed to be part of Russia's shadow fleet. It was reportedly sailing under an alleged false flag on its way to the port of Primorsk in Russia after departing from Santos, Brazil. Investigators were also alerted by the fact that the ship appeared unusually light and insufficiently loaded.
After the Coast Guard boarded and took control of the vessel, the captain, which is a Russian citizen, was taken in for questioning, however, he has not been arrested yet. Meanwhile, the Russian embassy in Sweden stated earlier today that it is "monitoring the situation", with Russian officials describing the boarding as an act of "piracy".
(via Göteborgs-Posten & Reuters)
🇸🇪#Sweden - 🇷🇺#Russia: Swedish special forces, along with aviation police and the coast guard, have seized a sanctioned Russian vessel which was sailing under a false flag.
The operation took place this Friday while the ship was sailing in Swedish territorial waters in the Baltic Sea near Trelleborg.
The ship was involved in the theft of grain from the territories that Russia has occupied since July 2025.
During last summer, the ship is said to have had its flag changed from a Russian flag to a Guinean flag.
(via Göteborgs-Posten)
🇸🇪#Sweden - 🇷🇺#Russia: The Swedish Coast Guard has boarded the Russian vessel ADLER in the Baltic Sea and carried out inspections on the ship which was reported to regularly transport military cargo to Russian allies in Africa.
The ADLER is operated by M Leasing LLC, a logistics company under EU sanctions and linked to the Russian Ministry of Defence.
The ship was forced to anchor off the Swedish coast yesterday morning after reportedly suffering an engine failure.
According to Swedish media, the crew is cooperating with the Swedish Coast Guard during the inspection.
(via Reuters; 📹 via @wartranslated on X)