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

Резултати

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

Пребарај: #frogs

当前筛选 #frogs清除筛选
Tesla Calls Official

@teslacallsofficial · Post #10006 · 14.03.2026 г., 22:17

🔥$FROGS Rolled the dice on this BSC play dip hunters know the drill: time it right, and always DYOR. X: https://x.com/christanxsx/status/2019762141427900628?s=46 🔗 Contract: https://solscan.io/token/0xC3B1A6229D9017376cF9a5Ba7a60782BD8dB4444 https://dexscreener.com/bsc/0x3357047F963d6459FB8C4e43c78392e09734e53C #FROGS#BSC#TESLACALLS

Interesting Planet 🌍

@interesting_planet_facts · Post #459 · 29.07.2025 г., 17:22

🌎 The mimic poison frog of Central America’s rainforests sports dazzling colors that copy other toxic frogs, deterring predators through clever visual deception rather than its own strong toxins. ✨ #rainforest⚡#mimicry⚡#frogs 👉subscribe Interesting Planet

Google Facts™ [ ️@googlefactss🌎]

@googlefactss · Post #40855 · 24.03.2026 г., 23:01

Boreal chorus frogs can make their loud, high-pitched “reeeek” calls underwater, which is rare among frogs. They are small frogs found in Canada and the northern United States, usually growing to about 3 centimeters long. Their bodies are brown, tan, or green, and they often have three dark stripes running down the back and a dark line through each eye. They live near ponds, marshes, and wetlands. Males call in groups to attract mates and warn other males. Calls are most common during the spring breeding season. 🐸🌿🌊 [Read more 1] [Read more 2] @googlefactss #Animals#Nature#Frogs#Wildlife#DidYouKnow#Communication#wednesdayfrog

Your Own Ads

@yourownads · Post #41 · 03.09.2024 г., 03:19

The Next #DOGS?! 🐸 FROGS 🐱 CATS 🐷 PIGS 🤑 BLUM 🐐 GOATS 🦆 DUCK ⭐️MAJOR 🌈These apps are similar to $DOGS. Some from them might be the next Airdrops, but nothing official announcement yet.! 🐦 Twitter 𝕏 ✔️ Follow us 💬Join Community ✔️ #aridrops#dogs#cats#frogs#pigs#blum#goats#duck#hamsterkombat

Venture Village Wall 🦄

@venturevillagewall · Post #3770 · 01.01.2025 г., 22:00

Telegram Unveils Major NFT Update 🎉 Telegram introduces a big update allowing gifts and stickers to be converted into NFTs. Gifts gain unique traits like emotions, backgrounds, and colors, enhancing their individuality and value. Rare traits will be limited to 10% of users, creating opportunities for resale at higher prices. Gifts can be converted for 25 Stars, while minting NFTs incurs network fees. Future integration with platforms like Fragment or GG is expected for seamless NFT creation. 🐸 The latest highlight is a unique frog gift gaining traction! For more details, visit: Full Update #Telegram#NFT#Gifts#Crypto#Updates#Blockchain#Stars#Minting#Fragment#GG#Frogs#RareItems#DigitalAssets#Community#Market#Trading#Tech#Innovation#SocialMedia#Engagement#CryptoTrends