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

Резултати

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

Пребарај: #futuremindssummit

当前筛选 #futuremindssummit清除筛选
Opportunities with Zula

@opportunities_zula · Post #1859 · 16.04.2026 г., 18:48

Yes, you heard it right! The Future Minds Summit covers your airfare, meals, accommodation, and even your visa costs. Eligibility: Open to Worldwide Participants 📍 Bangkok, Thailand 🇹🇭 🗓 Event Dates: 16-19 July 2026 ⏳ Deadline: 16 June 2026 👉 Apply here: https://thegyn.org/fms-thailand/ (link in bio) #FutureMindsSummit #Thailand #CallForDelegates#YouthLeadership#FundedOpportunity FMST

Opportunities with Zula

@opportunities_zula · Post #1845 · 15.04.2026 г., 10:44

📣 Call For Worldwide Applications! The Future Minds Summit Thailand 🇹🇭 2026 invites motivated youth from across the world to take part in a global leadership and Intellectual dialogue on Sustainable Development Goals in Bangkok, Thailand 🎓 Theme: Exploring Sustainability through Innovative Minds 🌍 Open to Worldwide Participants Scholarship Covers: ✈️ Airfare 🗄️ Visa Fees (if any) 🏨 Accommodation 🍽 Meals & Tea Breaks 📄 Visa support & Certification 🎙️ Speaking Opportunity at the Forum 🤝 All Social Activities & Cultural Fest 🗓 Event Dates: 16-19 July 2026 ⏳ Deadline: 16 June 2026 👉 Apply here: https://thegyn.org/fms-thailand/ #FutureMindsSummit #Thailand #CallForDelegates#YouthLeadership#FundedOpportunity

Opportunities with Zula

@opportunities_zula · Post #1857 · 16.04.2026 г., 15:42

Bangkok is Calling Future Leaders! Visit: https://tinyurl.com/fms-thailand2026 Applications are now open for the GYN FutureMinds Summit 2026 in vibrant Bangkok, Thailand Whether you're a student, graduate, or professional (ages 16–45), this is your chance to connect, learn, and lead on a global stage. No specific background required — just passion and vision! What’s Covered? Airfare Accommodation Meals & Tea Breaks Visa Support & Fees (if applicable) Speaking Opportunity Cultural Fest & Social Activities Certification Join a diverse network of changemakers, gain international exposure, and make your voice heard where it matters. Tag someone who shouldn’t miss this opportunity! #FutureMindsSummit#FullyFunded#YouthLeaders#GlobalOpportunities#Bangkok2026#Changemakers#ApplyNow