Один из самых удобных способов записать данные это использование готовых форматов, такие как 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
🚗✨ Exciting news! The updated Volvo XC90 is set to be unveiled on September 4th! 🌟
🔋 This refreshed model will feature a hybrid powertrain, ensuring it remains relevant until the brand transitions fully to electric vehicles by the end of the decade. ⚡️
Stay tuned for more updates!
#VolvoXC90#HybridPower#SustainableDriving#CarLaunch#Auto
🚗Exciting news for BMW fans! The new BMW M5 Touring will be unveiled on August 15 at Pebble Beach.
This innovative model will hit the US market in spring 2025, marking the first official M5 Touring available in the country.
Stay tuned for more updates!
#BMW#M5Touring#PebbleBeach#CarLaunch#Auto
🚗✨Introducing the Updated Kia K8 Sedan!🇰🇷
The all-new K8 features a completely redesigned front and a simplified interior architecture, enhancing both style and comfort. The rear has also been refreshed with the removal of fake exhaust tips. 🔥
Under the hood, South Korean buyers can choose from:
- 🛢️2.5L and 3.5L gasoline engines (198 or 300 hp)
- 🌱Hybrid powertrain based on a 1.6L engine delivering 230 hp
- 🔄 The 3.5L engine also offers a bi-fuel version with 240 hp and optional all-wheel drive!
💰 Starting price: 37.36 million won ( $27,000).
#KiaK8#Sedan#CarLaunch#KiaMotors#AutomotiveInnovation#LuxuryCars#Auto🚘🌟
🚗✨ Skoda Unveils the "Kulaak" in India! 🇮🇳
Introducing the new Kylaq crossover, measuring under 4 meters, set to hit the market in 2025! The name was chosen through a public vote and translates to "crystal" from Sanskrit. 💎
🔧 Engine Specs:
- 🏎️ 1.0 TSI engine with 115 hp
- 🔄 Available with a manual or automatic transmission
- 🚙 Front-wheel drive only
#SkodaKylaq#Crossover#CarLaunch#India#Innovation#Skoda#Automotive#Auto
🚘✨Introducing the Skoda Elroq Electric Crossover!✨🚘
The new Skoda Elroq is slightly larger than the Karoq, measuring 4488x1884x1625 mm with a wheelbase of 2765 mm. With a ground clearance of 186 mm, it’s ready for any adventure! 🌍💪
⚡️Performance Features:
- Available with electric motors producing 170, 204, or 286 hp.
- The top all-wheel-drive version boasts an impressive 299 hp! 🚀
- Range: From 375 to 560 km on a single charge! 🔋🌿
✅Simply Clever Innovations:
- Tire tread depth gauge integrated into the ice scraper! ❄️
- Elastic net under the luggage shelf for convenient charging cable storage! 📦🔌
ℹ️ The petrol Karoq starts at €33,100 in Germany, while the Elroq will be just €760 more! 💰🇩🇪
#SkodaElroq#ElectricCrossover#SimplyClever#SustainableDriving#CarLaunch#Auto#Innovation#Skoda
Audi has officially unveiled the new generation A6!
Now, this index belongs to electric vehicles — a liftback and an estate version.
🚘 The exterior of the new models is almost entirely copied from the namesake concepts, while the interior is inspired by the Q6 e-tron crossover.
🚢 The base version will be the rear-wheel drive A6 e-tron performance with a single motor producing 367 hp. For the S6, there will be two motors delivering 550 hp and accelerating from 0 to 100 km/h in just 3.9 seconds, with a top speed of 240 km/h.
🔋 In both cases, a 100 kWh battery is provided, allowing the single-motor versions to travel up to 756 km, while the all-wheel drive versions can reach up to 675 km.
ℹ️ Pre-orders will start in September, with prices starting at €75,600 for the standard version and €99,500 for the S6.
#Audi#A6#ElectricVehicles#ETRON#CarLaunch#LuxuryCars#Innovation#S6#Auto