Один из самых удобных способов записать данные это использование готовых форматов, такие как 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
News: #AU Chairperson calls for maximum restraint amid renewed tensions in #Tigray
The Chairperson of the African Union Commission, Mahmoud Ali Youssouf, has urged all parties in #Ethiopia’s Tigray region to exercise maximum restraint as tensions rise and reports emerge of renewed clashes in parts of the region.
In a statement issued on Friday, the AU Commission said its Chairperson is closely monitoring developments in Tigray and expressed deep concern over recent developments. He re-emphasized the paramount importance of preserving the “hard-won gains” achieved under the African Union-led Permanent Cessation of Hostilities Agreement (#COHA) signed between the federal government and the Tigray People’s Liberation Front (#TPLF) in Pretoria on 2 November 2022.
The Chairperson called on all parties to refrain from actions that could undermine confidence and to resolve outstanding issues through constructive dialogue, in full adherence to both the .....
Read more: https://addisstandard.com/?p=54840
News: #AU monitoring team returns to #Mekelle after tensions renew focus on #Pretoria agreement
An advance team of African experts under the African Union’s Monitoring, Verification and Compliance Mechanism (#AU-MVCM) has arrived in Mekelle, resuming its “mandate of monitoring the implementation” of the Permanent Cessation of Hostilities Agreement (#COHA), the AU Commission’s Political Affairs, Peace and Security Department said on today.
According to the Commission, the team redeployed after an “administrative break” to resume their mandate the office said was “crucial” to the implementation of the of the COHA, signed between the federal government and the #Tigray People’s Liberation Front (#TPLF) in November 2022.
The resumption of the task comes amid concerns over renewed tensions, clashes and drone strikes in parts of Tigray.
Last week, the AU Commission Chairperson Mahmoud Ali Youssouf ....
Read more: https://addisstandard.com/?p=54994
News: #TPLF says it ‘will not stay idle’ if #Pretoria deal is breached, urges AU, US, EU to move beyond concern statements
The chairman of the Tigray People’s Liberation Front (TPLF), Debretsion Gebremichael (PhD), has warned that the party “will not stay idle” if the Pretoria Cessation of Hostilities Agreement (#CoHA) is breached and the group comes under attack, while dismissing claims that it has been “weakened and dispersed.”
He also urged international actors including the African Union (#AU), the #United_States, and the European Union (#EU) to move beyond expressions of concern and take concrete action to safeguard the fragile peace process.
Speaking at a press briefing today, Debretsion rejected assertions that the TPLF has lost cohesion. “They say we are weakened and dispersed. But our answer is: we are not dispersed when it comes to our survival and security,” he said.
Debretsion also said he has been in frequent contact with representatives....
Read more: https://addisstandard.com/?p=55172
News: #Tigray opposition parties urge international mediators to intervene as tensions raise fears of renewed war
Several Tigray-based opposition political parties have issued separate open letters warning of an imminent risk of renewed conflict in the region and calling on international mediators and guarantors of the Cessation of Hostilities Agreement (#CoHA) to take urgent preventive action.
Salsay Weyane Tigray (#SaWeT) and the Tigray Independence Party (#TIP), in letters addressed to the #United_Nations, the African Union (#AU), the #United_States, the #European_Union, and other guarantors and facilitators of the Pretoria peace agreement, expressed deep concern over what they described as escalating political and military tensions that could unravel the fragile peace in Tigray.
In its open letter, SaWeT warned that the region is “on the brink of an absolutely preventable disaster,” saying that a growing military confrontation threatens the collapse of …..
Read more: https://addisstandard.com/?p=54847