Один из самых удобных способов записать данные это использование готовых форматов, такие как 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
🤔 What phrases do you know with 🐶 ‘dog’? 🤩 We’re here to help you learn 7 phrases so you can feel like ‘a top dog’! Scroll through the images – and ✍️ write some sample sentences of your own!
🥹 Researchers from Japan say dogs could cry happy tears when they see their owners. 😊 Learn more about this story by clicking on the link in our bio!
Images: Getty
#learnenglish#idiom#vocabulary#englishclass#IELTS
Are you a helpful person? 💪😊 Help us out by writing the missing word in this expression which means ‘If a lot of people help, a task can be completed quickly and easily’.
Are you happy to help when you’re needed? 👇👇👇
MORE: Click the link in our bio to learn another expression with 'hand' that you can use in similar situations! 👋👋👋
Image: Getty
#learnenglish#vocabulary#englishclass#phrases#expressions#idiom#learnenglish
Do you know someone who always thinks that everyone else has a better life than them?! 🙄😅 Scroll through the images to find out how to use ‘the grass is always greener on the other side’ 🌱, and don’t forget to answer the questions on the last slide!
EXTRA: Could walking 7,000 steps a day could improve your mental health? 🚶 Click the link in our bio to find out and learn some useful vocabulary in the process! 📰💚
Image: Getty
#vocabulary#learnenglish#englishlanguage#expression#idiom#proverb#englishclass#speakenglish
You know when somebody just WON’T change their ways? 😠 We’ve got an English expression for that! ✅
Scroll through the images to find out how to use ‘You can’t teach an old dog new tricks.’ ❌🐶
Can you use it in a sentence – and do you have a similar expression in your language? 👇👇👇
MORE: If you'd like to learn some more animal idioms, like 'rabbit on 🐰' or 'as sick as a parrot 🦜', click the link in our bio!
Image: Getty
#trick#proverb#learnenglish#vocabulary#learnenglish#englishlanguage#expression#idiom#englishclass#speakenglish
What you do is more important than what you say, right? 👍 Can you complete this English expression that means exactly that? Write your answer in the comments and don’t forget to give this post a like!
Do you have a similar expression in your language? 👇👇👇
Want to learn more English expressions and idioms? Click the link in our bio to listen to our podcast The English We Speak!
Image: Getty
#learnenglish#esl#efl#vocabulary#englishclass#phrases#expressions#idiom#learnenglish#britishenglish#informalenglish#slang
😃Even if nobody in your family is called Bob, you can still use this informal English expression to say that a task is really simple and easy! Write your answer in the comments and be sure to like this post! Do you have a similar expression in your language? 👇👇👇
🤩 MORE: Learn about the stories behind our names with this episode of ⏱️ 6 Minute English. Click the link in our bio NOW!
#idioms#esl#efl#vocabulary#englishclass#phrases#expressions#idiom#learnenglish#britishenglish#informalenglish#slang
It’s almost New Year – and we’ve got a great expression you can use to say that ‘things will be different from now on!’ 🎉🥳 Choose the correct word to fill the gap – we’ll tell you the answer later!
MORE: Click the link in our bio to see what our presenter's hopes, plans and dreams for 2025 were! 😄
Image: Getty
#learnenglish#newyear#happynewyear#freshstart#newbeginning#vocabulary#englishclass#phrases#expressions#idiom#learnenglish#britishenglish#informalenglish#slang
🤩 Even if you don’t eat meat, you can still use this expression to say that you’re super-hungry! 😁 Write your answer in the comments and like and share this post! Do you have a similar expression in your language? 👇👇🤩
MORE: ⁉️Are you angry when you're hungry? There's an English expression for that! 😲 Click the link in our bio to find out what it is with ⏱️ 6 Minute English!
Images: Getty
#learnenglish#hungry#starving#horse#esl#efl#vocabulary#englishclass#phrases#expressions#idiom#learnenglish#britishenglish#informalenglish#slang
🤔 Did something bad happen to you when you weren’t expecting it? You’re not going to put yourself in that situation again, are you? 😄 Learn this useful English expression that summarises this life lesson. Give this post a like, and ✍️ put your answer in the comments! Do you have a similar expression in your language?
🤩 Click on the link in our bio to learn some modern idioms!
Images: Getty
#learnenglish#advice#idioms#esl#efl#vocabulary#englishclass#phrases#expressions#oncebitten#britishenglish#lifelesson#inspiration#slang