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

Резултати

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

Пребарај: #playandearn

当前筛选 #playandearn清除筛选
SingSing Announcement

@singsingchannel · Post #824 · 23.09.2024 г., 13:00

🚨 RUBY Mining Feature is officially closed 🚨 But don’t worry! You can still earn RUBY by: 1️⃣ Completing Missions 2️⃣ Inviting Friends Keep the RUBY flowing! 💎 #SingSing#EarnRUBY#PlayAndEarn 🎤Announcement | Chat | X (Twitter) | Website | Game

SingSing Announcement

@singsingchannel · Post #914 · 21.10.2024 г., 13:09

🚨 Pssst, have you heard? SingSing's Big Airdrop is coming soon! 🚀 How to get this exclusive Airdrop Chance? It's super simple: just play Tycoon Game daily!🎤💸 Play Tycoon every day and get ready for the BIG Airdrop 💎✨ Are you ready to make it rain? 🌧 #SingSingAirdrop#PlayAndEarn#Tycoon 🎤Announcement | Chat | X (Twitter) | Website | Game

SingSing Announcement

@singsingchannel · Post #964 · 05.11.2024 г., 11:27

🎬 BOOM! SingSing’s brand-new TVC has landed! 🎬 Get ready to dive into the premier launchpool and social gaming platform! Where games, and epic rewards are just the beginning. 🎶💎 🔥 Watch now and catch the SingSing vibe! 👉 Video link: https://youtu.be/dneU7k6fnH0 Like, Share the TVC to earn $KARA Reward in Tycoon Game! #SingSing#TVC#SocialGaming#PlayAndEarn

Crypto Fight || News 🚀

@cryptofightnews · Post #3113 · 20.11.2025 г., 11:37

🎮GTBS Tap Tap Game Contest is LIVE! 💰 0.15M Lakh GTBS Coins Airdrop🔥For Top 1000 Players 🏆President Rewards 🥇 Top 1: 22,500 GTBS Coins 🥈 Top 2–100: 45,000 GTBS Coins (shared) 🥉 Top 101–1000: 82,500 GTBS Coins (shared) 📅Contest Ends: 8 Feb 2026 (90 Days Live!) 🚀 Play. Rank. Win. Earn GTBS! 🎯 Be among the first 1000 winners and grab your share today! 👉Join Now:https://t.me/gtbsapp_bot/?start=1169158525 #GTBSTapTap#GTBSChain#PlayAndEarn#GTBSGame#AirdropEvent#CryptoGaming#GTBSCommunity