Один из самых удобных способов записать данные это использование готовых форматов, такие как 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
Oil Market Balance May Return by April
An increase in traffic through the Strait of Hormuz by 5–6 tankers daily could restore market balance. Despite the London insurance market halt, up to 42% of the fleet under Liberia, Marshall Islands, Malta, and Bahamas flags are shifting to Chinese and Indian state guarantees. Panama and Singapore’s flexible fleets adapt faster, while Iran and Hong Kong’s “shadow fleet” bypass sanctions and remain active.
#oil#market#sanctions#Russia#maritimetraffic
The main news of Russia and the world ishere.
🚀 Increase in Ship Traffic Through Strait of Hormuz Observed
On April 10, the number of ships passing through the Strait of Hormuz increased to nine, according to data from shipping intelligence company Kpler. According to BlockBeats, this marks a rise from the previous day's count of five vessels, although it remains below the broader normalized levels.
#Shipping#StraitOfHormuz#MaritimeTraffic#Kpler#BlockBeats
🚀 Strait of Hormuz Traffic Halts Following U.S. Maritime Blockade
All maritime traffic through the Strait of Hormuz has reportedly ceased after U.S. President Donald Trump declared a maritime blockade via social media. According to NS3.AI, information from British sources, as reported by CCTV News, indicated that the blockade had been in place for several hours. While traffic was still feasible on the 12th, at least two vessels attempting to exit the strait reversed course. Tanker traffic had seen a slight uptick on the 11th before declining on the 12th.
#StraitOfHormuz#MaritimeBlockade#USPresident#DonaldTrump#TankerTraffic#CCTVNews#NS3AI#MaritimeTraffic
🚀 Iran Considers Bitcoin Toll for Ships in Strait of Hormuz
Iran is contemplating a new toll system for ships passing through the Strait of Hormuz, potentially requiring a $1-per-barrel fee payable in Bitcoin. According to NS3.AI, Hamid Hosseini, spokesperson for Iran’s Oil, Gas, and Petrochemical Products Exporters’ Union, indicated that this move could significantly impact maritime traffic. Arkham, a maritime analytics firm, estimates that a typical cargo ship carrying around 3 million barrels would face a payment of approximately $3 million in Bitcoin. Martin Kelly, head of advisory at maritime intelligence group EOS Risk, noted that this regulation could reduce the number of ships allowed to pass through the strait to 10–15 per day, a sharp decrease from the current average of about 135 ships.
#Iran#Bitcoin#Toll#StraitOfHormuz#Shipping#MaritimeTraffic#Oil#Cryptocurrency#Petrochemical#MaritimeRegulation#BTC
🚀 WTI Crude Oil Rises 10% Amid U.S.-Iran Peace Talks Stalemate
WTI crude oil experienced a significant intraday increase of 10%, reaching $105.33 per barrel, following the conclusion of the initial round of U.S.-Iran peace talks in Islamabad, which ended without an agreement. According to NS3.AI, the U.S. Central Command announced plans to block all maritime traffic to and from Iranian ports starting at 2:00 p.m. UTC on April 13. The U.S. military clarified that vessels traveling through the Strait of Hormuz to non-Iranian ports will not encounter any restrictions.
#WTI#CrudeOil#USIranPeaceTalks#MaritimeTraffic#Iran#StraitOfHormuz#USTechnology#NS3AI#CentralCommand#OilPrices