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 слични објави

Пребарај: #residency

当前筛选 #residency清除筛选
Gyotе-Institut O'zbekiston

@goetheinstituttaschkent · Post #5013 · 08.01.2025 г., 11:08

🎭 Frankfurt LAB Residency Programme: Frankfurt Moves! 2025 🎶 Das Frankfurt LAB und die KfW Stiftung bieten aufstrebenden Künstlerinnen aus den Bereichen Darstellende Künste (Performance, Tanz, Theater, Musik) eine vierwöchige Residenz in Frankfurt am Main. Zielgruppen sind Künstlerinnen, die in Afrika, Asien, Lateinamerika oder der MENA-Region ausgebildet wurden. 📅 Zeitraum der Residenz: 21. Juli bis 17. August 2025 🌍 Offen für: Künstler*innen mit erster professioneller Erfahrung und einer Projektidee für die Residenz 💼 Bewerbung bis: 26. Januar 2025 Was wird geboten? Stipendium (max. 4.000 € brutto) Unterkunft & Reisekosten (1-2 Personen) Technische und dramaturgische Unterstützung Zugang zu professionellen Proberäumen und Präsentationsmöglichkeiten 🔗 Alle Infos und Bewerbung: Link zur Ausschreibung #FrankfurtMoves2025#Residency#Kunstförderung#PerformingArts#FrankfurtLAB#KfWStiftung English: 🎭 Frankfurt LAB Residency Programme: Frankfurt Moves! 2025 🎶 Frankfurt LAB and KfW Stiftung offer emerging artists in the performing arts (performance, dance, theatre, music) a four-week residency in Frankfurt am Main. The programme is aimed at artists who have trained in Africa, Asia, Latin America, or the MENA region. 📅 Residency period: July 21 to August 17, 2025 🌍 Who can apply: Artists with first professional experience and a project idea for the residency 💼 Application deadline: January 26, 2025 What’s offered? Stipend (max. 4,000 € gross) Accommodation and travel expenses (for 1-2 people) Technical and dramaturgical support Access to professional rehearsal spaces and presentation opportunities 🔗 For more information and application: Full announcement link #FrankfurtMoves2025#Residency#ArtSupport#PerformingArts#FrankfurtLAB#KfWStiftung

Crypto M - Crypto News

@CryptoM · Post #65051 · 10.04.2026 г., 16:36

🚀 Nvidia CEO Encourages Relocation to California Amid Tax Concerns Nvidia Corp. Chief Executive Officer Jensen Huang has encouraged individuals to consider moving to California, despite the state's high tax rates. Bloomberg posted on X, highlighting Huang's remarks, which come at a time when several billionaires have recently left California due to the potential imposition of a new tax levy. Huang's comments underscore the ongoing debate about the state's tax policies and their impact on residency decisions. #Nvidia#JensenHuang#California#Taxes#Relocation#Billionaires#TaxPolicy#Residency