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

Резултати

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

Пребарај: #kashkadarya

当前筛选 #kashkadarya清除筛选
EKOLOG.UZ| ENG

@ekologuzenglish · Post #12420 · 17.04.2026 г., 09:59

#Kashkadarya Spring is the breath of nature, the heartbeat of our land. When fields are covered with scarlet tulips, it feels as if the earth itself has dressed in festive colors… 🌺 Yet sadly, there are those who, instead of admiring this beauty, consider destroying it a “heroic” act. A video circulating on social media shows a car with the license plate 70 R418XA and two other vehicles driving over fields of tulips, crushing not only the flowers but also the insects and reptiles that live there. What is most disturbing is that they record this cruelty with laughter and a sense of “pride”… This is not just a violation. This is violence against nature. This is a clear manifestation of moral degradation. Tulips are not just flowers. They are a symbol of spring, a vital part of the ecosystem, and a habitat for thousands of living beings. Destroying them means breaking an entire chain of life. The exact location of the incident is unknown, but based on the license plate, it is likely that it took place in the Kashkadarya region. In this regard, we call on the Kashkadarya Regional Department of Ecology to provide a legal assessment of this incident and hold those responsible accountable under the law. Nature does not belong to us. We are only its guests. If we fail to protect beauty, we will fail to protect the future… 🌍 ☘️Read the latest environmental news on the @ekologuz page. Follow us and send your suggestions and wishes via @eklguz_bot Instagram | Facebook | Twitter | Sayt | Youtube.

Hashtags

Teach For Uzbekistan | Official

@teachforuzbekistan · Post #300 · 21.10.2025 г., 14:07

Qashqadaryodagi fellowlarimiz faoliyatlarining ikkinchi yilini davom ettirar ekan, ular uchun loyihani samarali boshqarish va project management tamoyillarini amaliy o‘rganishga bag‘ishlangan sessiya tashkil etildi. 📆 18–19-oktabr kunlari o‘tkazilgan mazkur sessiyada fellowlar ta’limdagi tashabbuslarni rejalashtirish, resurslarni boshqarish va jamoaviy ishni samarali yo‘lga qo‘yish bo‘yicha tajriba almashishdi. 💡 Sessiya BMT Taraqqiyot dasturi (UNDP) start-up tashabbuslar loyihasi mentori Barnoxon Artikxodjayeva tomonidan olib borildi. 😎Teach For Uzbekistan jamoasi Barnoxon Artikxodjayevaga o‘z tajribasi va qo‘llab-quvvatlovi uchun samimiy minnatdorlik bildiradi! #TeachForUzbekistan#FellowDevelopment#ProjectManagement#Qashqadaryo#EducationForAll 💬💬💬 As our fellows in Kashkadarya continue their second year of activities, a session was organized to strengthen their skills in effective project management and the practical application of project management principles. 📆 Held on October 18–19, the session focused on planning educational initiatives, managing resources, and fostering effective teamwork. 💡 The session was conducted by Barnokhon Artikkhodjaeva, mentor of the UNDP Start-up Initiatives Project. 😎The Teach For Uzbekistan team extends its sincere gratitude to Barnokhon Artikkhodjaeva for her valuable insights and continuous support! #TeachForUzbekistan#FellowDevelopment#ProjectManagement#Kashkadarya#EducationForAll 📱Instagram🕊Telegram🔹Linkedin📱Facebook📺YouTube🌍Veb sayt