TGTGInsighttelegram intelligenceLIVE / telegram public index
← Python Заметки

TGINSIGHT SIMILAR POSTS

Најди сличен содржај

Изворен канал @pythonotes · Post #397 · 12 ное.

Использование Pydantic сегодня стало нормой, и это правильно. Но иногда на ревью вижу, что используют его не всегда корректно. Например, метод BaseModel.model_dump() по умолчанию не преобразует стандартные типы, такие как datetime, UUID или Decimal, в простой сериализуемый для JSON вид. Тогда пишут кастмоный сериализатор для этих типов чтобы функция json.dump() не падала с ошибкой. import uuid from datetime import datetime from decimal import Decimal from uuid import UUID from pydantic import BaseModel class MyModel(BaseModel): id: UUID date: datetime value: Decimal obj = MyModel( id=uuid.uuid4(), date=datetime.now(), value='1.23' ) print(obj.model_dump()) # не подходит для json.dump # { # 'id': UUID('4f8c1bc4-25fd-40cd-9dbe-2c73639b0dc1'), # 'date': datetime.datetime(2025, 12, 12, 12, 12, 12, 111111), # 'value': Decimal('1.23') # } # добавляем свой кастомный сериализатор json.dumps(obj.model_dump(), cls=MySerializer) # { # 'id': '4f8c1bc4-25fd-40cd-9dbe-2c73639b0dc1', # 'date': '2025-12-12T12:12:12.111111', # 'value': '1.23' # } В данном случае класс MySerializer обрабатывает datetime, UUID и Decimal. Например так: class MySerializer(json.JSONEncoder): def default(self, o): if isinstance(o, Decimal): return str(o) elif isinstance(o, datetime): return o.isoformat() elif isinstance(o, UUID): return str(o) return super().default(o) Специально для тех, кто всё еще так делает - в этом нет необходимости! Pydantic может это сделать сам, просто нужно добавить параметр mode="json". json.dumps(obj.model_dump(mode="json")) # { # 'id': '4f8c1bc4-25fd-40cd-9dbe-2c73639b0dc1', # 'date': '2012-12-12T12:12:12.111111', # 'value': '1.23' # } #pydantic#libs

Резултати

Пронајдени 11 слични објави

Пребарај: #airquality

当前筛选 #airquality清除筛选
Amazing Geography 🌍

@amazingeo · Post #338 · 06.10.2025 г., 12:31

🌍 Remote sensing satellites can now detect wildfire smoke plumes traveling thousands of kilometers. These space-based observations help track air quality and protect health far beyond fire zones. ✨ #remote⚡#sensing⚡#satellites⚡#airquality⚡#geography⚡#nature⚡#earth 👉subscribe Amazing Geography 👉more Channels ​

Green University CA | Official

@centralasian_greenuniversity · Post #314 · 08.11.2025 г., 09:47

⏸A powerful video by our students raising awareness about the dangers of air pollution. #AirQuality#Sustainability#EcoEducation#GreenUniversity#ActNow ✉️[email protected] ☎️ +998 55 512 00 77 📍Location 🌐Website | 📱Telegram | 📱Instagram | 📱LinkedIn | 🟥YouTube

Green University CA | Official

@centralasian_greenuniversity · Post #468 · 05.12.2025 г., 10:07

Co-creation Workshop on Climate and Air Quality 💬On December 4, Green University, together with Clean Air Asia and with the support from MOEJ, hosted a workshop in Tashkent focused on developing projects to improve air quality and reduce emissions. The workshop highlighted the JCM, project idea development, and knowledge exchange with international experts. The workshop: ⚪️Helped to explore the co-benefits of clean air and climate mitigation 🔵Introduced the Joint Crediting Mechanism (JCM) as a financing tool for low-carbon projects 🔴Developed Project Idea Notes (PINs) with city officials and experts 🟢Facilitated knowledge exchange with specialists from Japan and Asia #GreenUniversity#AirQuality#ClimateAction#SustainableCities#CleanAirAsia#JCM#Uzbekistan#EnvironmentalLeadership ✉️[email protected] ☎️ +998 55 512 00 77 📍Location 🌐Website | 📱Telegram | 📱Instagram | 📱LinkedIn | 🟥YouTube

Green University CA | Official

@centralasian_greenuniversity · Post #559 · 17.12.2025 г., 07:21

Air Quality Assessment in Termez 2025: Toward Cleaner Air and Clearer Skies 🔴On December 16, 2025, Green University, together with UNEP and the Finnish Meteorological Institute, presented the results of the air quality assessment in Termez. The event brought together government representatives, experts, development partners, media, and civil society. 🔴The assessment, conducted at the request of the National Committee on Ecology and Climate Change of Uzbekistan, was based on data from the first automatic reference air monitoring station installed in Termez in 2024 with the support of the Zamin Foundation. The study identified key pollution sources and provided science-based recommendations to improve air quality. 🔴The discussion also covered new air quality management strategies, including the work of Uzhydromet and youth-focused environmental initiatives by the Zamin Foundation. #AirQuality#CleanAir#Termez#Uzbekistan#GreenUniversity#UNEP#FMI#ClimateAction#EnvironmentalProtection ✉️[email protected] ☎️ +998 55 512 00 77 📍Location 🌐Website | 📱Telegram | 📱Instagram | 📱LinkedIn | 🟥YouTube