Один из самых удобных способов записать данные это использование готовых форматов, такие как 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 Final Pagani Zonda Unveiling! 🎉
On August 16, the last and 140th Zonda, named Arrivederci (Italian for "Goodbye"), will be revealed after 12 years of craftsmanship! 🇮🇹❤️
This stunning masterpiece features a full carbon fiber body, showcasing the pinnacle of automotive engineering. 🏎️💨
While details about the engine remain under wraps, it's likely to house the iconic 7.3L V12 from Mercedes-AMG, delivering a monstrous 760 hp and 780 Nm of torque! 🔥⚙️
#PaganiZonda#Arrivederci#Supercar#CarEnthusiast#AutomotiveArt#Auto🚀🌟
🚗💨 Exciting news from Mansory! They've just unleashed a stunning upgrade for the Ferrari F8 Spider! 🎉
🔧 The iconic 3.9L V8 engine has received a serious boost, now delivering an impressive 880 horsepower and 960 Nm of torque! 💪🔥
🏎️ This beauty, named Tempesta Turchese, can sprint from 0 to 100 km/h in just 2.6 seconds and reach a top speed of 354 km/h! 🚀 Compare that to the stock F8 Spider's 2.9 seconds and 340 km/h, and you can see the difference! 😍
#FerrariF8#Mansory#TempestaTurchese#CarEnthusiast#Supercar#LuxuryCars#Auto
🚗✨Lexus Unveils Upgraded LC Coupe and Convertible!✨🚗
Since its debut in 2017, the Lexus LC family has received a sleek exterior makeover and new interior materials. But that's not all! The updated models now feature a stiffer chassis, thanks to additional braces installed under the floor near the front and rear axles, enhancing overall handling. 🏎️💨
Under the hood, the Lexus LC offers a powerful lineup: a 5.0L V8 engine producing 477 hp or a hybrid V6 powertrain with a 3.5L engine delivering 359 hp. 🔥🔋
#LexusLC#LuxuryCars#CarEnthusiast#DrivingExperience#AutoNews#V8Power#Auto
🚗💨Mansory Unleashes the Beast: 1050 HP Audi RS 7!💥
In its stock form, the Audi RS 7 boasts a powerful 4.0L V8 twin-turbo engine delivering 630 hp and 850 Nm of torque. But Mansory has taken it to the next level, tuning it to an astonishing 1050 hp and 1199 Nm! 🔥💪
The stunning carbon fiber body kit includes:
- Front bumper with splitter 🏎️
- Rear bumper with diffuser 🚀
- Eye-catching rear spoiler 🕶️
- Mirror caps and side skirt trims ✨
#Mansory#AudiRS7#Supercar#CarEnthusiast#Tuning#LuxuryCars#Performance#Auto
🚗✨Exciting News for Honda Fans!✨🚗
The Honda Civic has just unveiled its new RS version with a manual transmission! 🎉 This sporty hatchback is designed for the Japanese market and fills the gap between the standard Civic and the high-performance Type R.
Key Features of the RS:
🔧 Enhanced suspension with new dampers for a firmer ride
🛠️ Improved steering for better handling
🛑 Upgraded brakes for superior stopping power
💪 Powered by a 1.5-liter engine producing 183 HP and 240 Nm of torque! 🏁💨
#HondaCivic#CivicRS#ManualTransmission#CarEnthusiast#Hatchback#Auto
🚗💨Manhart Unleashes 200+ Extra Horses on the Toyota Supra!🏎️✨
The stock 3.0L inline-six engine of the Toyota Supra packs a punch with 340 hp. But the tuning experts at Manhart have taken it to the next level, boosting it to an impressive 550 hp and a whopping 770 Nm of torque! ⚡️🔧
But that’s not all! The stunning coupe also features:
- Eye-catching aerodynamic body kit 🛠️
- Re-tuned suspension for enhanced performance 🏁
- New wheels for that perfect look! 🖤
🛒 Individual parts available:
- Engine upgrade: €11,999
- New exhaust system: €5,050
- Body kit: €13,500
- Wheels: €3,070 per set
- Coilovers: €3,100 per set
#Manhart#ToyotaSupra#Tuning#CarEnthusiast#PerformanceUpgrade#CarLovers#Auto
🚗💨Unveiling the Lotus Theory 1: A 1000-HP Marvel!🌟
Get ready to be amazed by the all-carbon supercar that redefines performance! With a compact length of just 4.5 meters, the Theory 1 features a unique door design that lifts up while sliding back. 🚪✨
🔋Power & Performance:
- 1000 HP💥
- 0-100 km/h in just 2.5 seconds⏱️
- Top speed exceeding 320 km/h🚀
- Equipped with a 70 kWh battery for a range of 400 km⚡
- Weighs in at an impressive 1.6 tons⚖️
#LotusTheory1#Supercar#ElectricPerformance#CarEnthusiast#Innovation#FutureOfDriving#LuxuryCars#Auto
🌟 Exciting News for Supercar Enthusiasts! 🚗💨
The British have officially kicked off production of the stunning Ginetta Akula! 🦈✨
First unveiled in 2019, this masterpiece is limited to just 20 units, starting at £275,000. 💰
Featuring a classic design, the Akula boasts a powerful 6.4L V8 engine with 600 hp, paired with a manual transmission and rear-wheel drive. 🔥 Despite its robust engine, it weighs only 1.2 tons, accelerating from 0 to 100 km/h in just 2.9 seconds! ⚡️🏁 With a top speed of 290 km/h, this beauty is ready to roar!
Are you ready to experience the thrill? 😍
#GinettaAkula#Supercar#LimitedEdition#V8Power#CarEnthusiast#LuxuryCars#SpeedDemon#Auto
🚗✨Introducing the Updated Audi A3 Hatchback: A Powerful Hybrid!✨🚗
⚙️ The heart of this beauty is the new 1.5 TFSI evo2 engine, replacing the previous 1.4-liter four-cylinder. With an increased compression ratio and higher fuel injection pressure, it's ready to impress! 💥
🔋 Coupled with a 116-hp electric motor, the 40 TFSI e variant produces a total of 204 hp and 350 Nm of torque, accelerating from 0 to 100 km/h in just 7.4 seconds! 🚀 Max speed? A thrilling 225 km/h! 🌟
🔥 For those craving more power, the 45 TFSI e variant boasts 272 hp and 400 Nm, hitting 100 km/h in just 6.3 seconds and a top speed of 237 km/h! 🏁💨
🛒 Orders are now open starting at €44,200!
#AudiA3#HybridPower#Innovation#LuxuryCars#CarEnthusiast#Performance#AudiLife#Auto🌍💚
🚗✨ Updated Audi RS 3: Hatchback and Sedan Debut! ✨🚗
🔧 The facelift brings a fresh look with new headlights featuring a checkered flag design for the daytime running lights, which can be customized! 🏁
🛠️ Inside, you’ll find a revamped steering wheel that’s now flat on both the top and bottom, complete with two new red buttons to activate RS Performance and RS Individual modes! 🔴🔵 Optional carbon bucket seats offer enhanced support for those thrilling drives. 🪑💨
💥 The Audi RS 3 retains its powerful 2.5-liter turbocharged five-cylinder engine, delivering 400 hp and 500 Nm of torque, paired with a seven-speed dual-clutch transmission and all-wheel drive. ⚡️💪 It still rockets from 0 to 100 km/h in just 3.8 seconds, with a top speed of 290 km/h! 🚀
🔄 Engineers have fine-tuned the torque splitter algorithm (RS Torque Splitter) and optimized chassis settings, allowing drivers to tackle corners at higher speeds! 🏎️💨
#AudiRS3#Performance#CarEnthusiast#TurboPower#LuxuryCars#DrivingExperience#Innovation#Auto🚘💖
🚗✨ Get Ready for the Modern Audi Sport Quattro! ✨🚗
On August 16th, the highly anticipated modern replica of the iconic Audi Sport Quattro will be unveiled live! 🎉🔥
Announced three years ago, this stunning electric powerhouse from German startup E-Legend boasts an impressive 816 horsepower!⚡💪 With only 30 units planned for production, this exclusive ride is set to turn heads! 😍
#AudiSportQuattro#ELegend#ElectricPower#CarEnthusiast#Supercar#ComingSoon#Auto
🚗✨Supercar Pagani Zonda Gets a Manual Transmission!🔧
In a stunning transformation, this iconic roadster has been upgraded with a manual gearbox at the request of renowned collector Mike Iney. 🏎️💨
Powered by a monstrous 760-hp Mercedes-AMG V12 engine with a 7.3-liter displacement, this beauty is ready to deliver an unforgettable driving experience!🔥
#PaganiZonda#ManualTransmission#Supercar#CarEnthusiast#MikeIney#AMGV12#Auto