Один из самых удобных способов записать данные это использование готовых форматов, такие как 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
A female Aedes mosquito gets infected with the Dengue virus when it bites a person infected with dengue. It then transmits dengue to other healthy individuals it goes on to bite.
Help to break the dengue transmission cycle!
✅ Everyone should use insect repellent and carry out other S-A-W actions to protect themselves from being bitten by mosquitoes.
✅ Those diagnosed with or suspected to be infected with dengue are also advised to avoid further mosquito bites, to prevent passing on the Dengue virus to mosquitoes and other people in their neighbourhoods.
S-A-W:
✅ Spray insecticide in dark corners around the house
✅ Apply insect repellent regularly
✅ Wear long-sleeve tops and long pants
📱 Download the myENV app to receive alerts on high Aedes mosquito populations near you, or visit go.gov.sg/dengue-high-risk
#DenguePrevention
Heading out for holiday adventures? Before you dash, don’t give the mozzies any room to stay!
Follow the B-L-O-C-K steps and mozzie-proof your home before you roam:
✅ Break up hardened soil
✅ Lift and empty flowerpot plates
✅ Overturn pails and wipe their rims
✅ Change water in vases
✅ Keep roof gutters clear and place BTI insecticide
Let’s make this holiday season not only merry but also mindful.
#BLOCKDengue#DenguePrevention
Going on your festive holiday escapade? 🏖
Give the mozzies no room to stay! Follow the B-L-O-C-K steps and mozzie-proof your home before you roam:
✅ Break up hardened soil
✅ Lift and empty flowerpot plates
✅ Overturn pails and wipe their rims
✅ Change water in vases
✅ Keep roof gutters clear and place BTI insecticide
Together, we can keep dengue at bay. Learn more: https://go.gov.sg/mozzieproof
#BLOCKDengue#DenguePrevention
#SGDengueUpdate The number of active dengue clusters reported continues to remain high, with 64 active clusters reported as of 28 Dec. 198 dengue cases were reported in the week ending 26 Dec, and the cumulative number of dengue cases for this year stands at more than 35,100.
Let’s keep up our #DenguePrevention efforts and continue doing the #MozzieWipeout at least once a week. Find out what else you can do to protect yourself and your family at go.gov.sg/mozzieproof
#SGDengueUpdate As of 17 Dec 2020, there have been 34,844 reported dengue cases this year, with 228 cases reported last week. While NEA has closed about 98% of the dengue clusters notified since the beginning of 2020, there are still over 230 residential areas with high Aedes aegypti mosquito population currently.
So let’s stay vigilant and keep up our #DenguePrevention efforts. If you’re planning to go for a staycation, don’t forget to do the #MozzieWipeout first! Learn more: go.gov.sg/mozzieproof
🦟They’re small, they’re pesky, and they’re definitely not welcome! Mosquitoes love stagnant water - don’t let them crash the party.
It’s time for a Real-World Quest! Carry out the #BLOCKdengue steps at least once a week and mozzie-proof your home:
✅ Break up hardened soil
✅ Lift and empty flowerpot plates
✅ Overturn pails and wipe their rims
✅ Change water in vases
✅ Keep roof gutters clear and place BTI insecticide
#DenguePrevention#Minecraft
Don't let your home become the Upside Down for mozzies! 🦟
The #BLOCKdengue steps are your weekly defence against these tiny monsters. Do these at least once a week:
✅ Break up hardened soil
✅ Lift and empty flowerpot plates
✅ Overturn pails and wipe their rims
✅ Change water in vases
✅ Keep roof gutters clear and add BTI insecticide
#DenguePrevention#StrangerThings