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

Резултати

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

Пребарај: #comingsoon

当前筛选 #comingsoon清除筛选
HDB

@SingaporeHDB · Post #982 · 21.10.2021 г., 01:35

#ComingSoon: An integrated development at Yew Tee which will house 2-room Flexi flats for seniors, a community club, a polyclinic, retail shops, and Choa Chu Kang’s first hawker centre all under one roof! P.S. The 2-room Flexi flats will be launched in the upcoming November sales exercise, along with over 4,000 flats in Hougang, Jurong West, Kallang/Whampoa and Tengah 😊 (Photo credit: MKPL Architects)

Hashtags

SingSing Announcement

@singsingchannel · Post #852 · 28.09.2024 г., 05:57

🚨The SingSing Tycoon NFT Marketplace is on its way🚨 💥 Trade exclusive NFTs for profits. 💎 Flex your collection. 🎮 Unlock game-changing assets. Get ready to take your SingSing Tycoon experience to the next level! 🚀 🔜 Your favorite NFTs, all in one place—stay tuned for more details 👀 #NFT#SingSingMarketplace#ComingSoon 🎤Announcement | Chat | X (Twitter) | Website | Game

SingSing Announcement

@singsingchannel · Post #972 · 08.11.2024 г., 11:21

🚀 Big News Alert 🚀 $SING is gearing up for an exciting CEX listing next week! 📈 But we’re keeping the exchange a secret…for now! 🤫 Guess the CEX & get ready for the reveal! 🔥 #SingSing#CEXListing#ComingSoon 🎤Announcement | Chat | X (Twitter) | Website | Game

MXPlayer Official

@mxofficialchannel · Post #1267 · 27.03.2026 г., 09:36

Kaptaan | Official Teaser | Amazon MX Player Language: Hindi Genre: Drama, Crime, Thriller jahan insaaf ki zarurat ho, wahan Kaptaan ki entry pakki hai ⚖️🔥 Kaptaan, coming soon, only on Amazon MX Player for FREE! watch now🔗- https://youtu.be/X4Kb6K7B61o #Kaptaan#AmazonMXPlayer#ComingSoon

MXPlayer Official

@mxofficialchannel · Post #1263 · 25.03.2026 г., 08:34

Famously Fit with Sophie | Official Trailer | Amazon MX Player Language: Hindi Genre : Fitness based Chat Show Bollywood fitness secrets, finally out 👀 Famously Fit with Sophie, coming soon only on Amazon MX Player for FREE! watch now - https://youtu.be/Cs6lCuRgBC8 #AmazonMXPlayer#ComingSoon#FamouslyFitwithSophie

Quasark.io - Announcement

@quasark_channel · Post #7 · 04.07.2023 г., 07:49

📢CLOSED BETA WHITELIST CLOSED Attention, QuasarK Community: the application period for our closed beta is now officially closed. We want to express our heartfelt thanks ❤️ to everyone who applied and showed their interest in being a part of this exclusive testing phase. Your support and enthusiasm mean the world to us! 👏 🚀 But hold on tight, because the journey is just getting started! In a matter of days we’ll be reaching out to our whitelisted beta testers🏆. If you made it to the whitelist, keep an eye on your notifications and direct messages 📩 as we will be sharing important updates and instructions with you. BEWARE OF SCAM! Stay tuned for more updates and announcements 👀 as we continue to make progress towards the launch of QuasarK. We appreciate your ongoing support and look forward to embarking on this exciting journey together! #QuasarK#ClosedBeta#BetaTesters#ComingSoon

ПретходнаСтраница 1 од 4Следна