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

Резултати

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

Пребарај: #metagram

当前筛选 #metagram清除筛选
Airdrop Market Pro

@airdrop_market_pro · Post #1386 · 02.10.2025 г., 15:08

💎 MetaGram Presale — Early Investors’ Edge! Be among the first to secure $MGR before listing at $0.0519. ⚡️ Buy & Earn instantly with our new swap-style UI: 0.001 BNB → 50 $MGR (free airdrop) 0.01 BNB → 500 $MGR 🤝 Referrals: +50% $MGR & +50% BNB back 🔥 Early entry = maximum upside. Don’t wait until the price goes public. 👉metagram.digital #MetaGram#Presale#BNB#Crypto

Airdrop Market Pro

@airdrop_market_pro · Post #1385 · 01.10.2025 г., 20:18

We’ve refreshed the MetaGram presale page! New swap-style UI = faster, clearer, mobile-friendly buying. 🚀 Don’t miss the Presale & Airdrop 💎 0.001 BNB → 50 $MGR (airdrop) ⚡️ 0.01 BNB → 500 $MGR 🤝 Referrals: +50% $MGR & +50% BNB 🔥 Listing price: $0.0519 / MGR 👉https://metagram.digital/airdrop #MetaGram#BNB#Presale#Crypto

Airdrop Market Pro

@airdrop_market_pro · Post #1383 · 29.09.2025 г., 16:38

We’ve refreshed the MetaGram presale page! New swap-style UI = faster, clearer, mobile-friendly buying. 🚀 Don’t miss the Presale & Airdrop 💎 0.001 BNB → 50 $MGR (airdrop) ⚡️ 0.01 BNB → 500 $MGR 🤝 Referrals: +50% $MGR & +50% BNB 🔥 Listing price: $0.0519 / MGR 👉https://metagram.digital/airdrop #MetaGram#BNB#Presale#Crypto

NFT & Airdrop News

@airdrop_nft1 · Post #1382 · 02.10.2025 г., 15:08

💎 MetaGram Presale — Early Investors’ Edge! Be among the first to secure $MGR before listing at $0.0519. ⚡️ Buy & Earn instantly with our new swap-style UI: 0.001 BNB → 50 $MGR (free airdrop) 0.01 BNB → 500 $MGR 🤝 Referrals: +50% $MGR & +50% BNB back 🔥 Early entry = maximum upside. Don’t wait until the price goes public. 👉metagram.digital #MetaGram#Presale#BNB#Crypto

NFT & Airdrop News

@airdrop_nft1 · Post #1381 · 01.10.2025 г., 20:18

We’ve refreshed the MetaGram presale page! New swap-style UI = faster, clearer, mobile-friendly buying. 🚀 Don’t miss the Presale & Airdrop 💎 0.001 BNB → 50 $MGR (airdrop) ⚡️ 0.01 BNB → 500 $MGR 🤝 Referrals: +50% $MGR & +50% BNB 🔥 Listing price: $0.0519 / MGR 👉https://metagram.digital/airdrop #MetaGram#BNB#Presale#Crypto

NFT & Airdrop News

@airdrop_nft1 · Post #1379 · 29.09.2025 г., 16:38

We’ve refreshed the MetaGram presale page! New swap-style UI = faster, clearer, mobile-friendly buying. 🚀 Don’t miss the Presale & Airdrop 💎 0.001 BNB → 50 $MGR (airdrop) ⚡️ 0.01 BNB → 500 $MGR 🤝 Referrals: +50% $MGR & +50% BNB 🔥 Listing price: $0.0519 / MGR 👉https://metagram.digital/airdrop #MetaGram#BNB#Presale#Crypto

Free Airdrop News 🔥🔥🔥

@free_airdrop_nn · Post #1165 · 02.10.2025 г., 15:08

💎 MetaGram Presale — Early Investors’ Edge! Be among the first to secure $MGR before listing at $0.0519. ⚡️ Buy & Earn instantly with our new swap-style UI: 0.001 BNB → 50 $MGR (free airdrop) 0.01 BNB → 500 $MGR 🤝 Referrals: +50% $MGR & +50% BNB back 🔥 Early entry = maximum upside. Don’t wait until the price goes public. 👉metagram.digital #MetaGram#Presale#BNB#Crypto

Free Airdrop News 🔥🔥🔥

@free_airdrop_nn · Post #1164 · 01.10.2025 г., 20:18

We’ve refreshed the MetaGram presale page! New swap-style UI = faster, clearer, mobile-friendly buying. 🚀 Don’t miss the Presale & Airdrop 💎 0.001 BNB → 50 $MGR (airdrop) ⚡️ 0.01 BNB → 500 $MGR 🤝 Referrals: +50% $MGR & +50% BNB 🔥 Listing price: $0.0519 / MGR 👉https://metagram.digital/airdrop #MetaGram#BNB#Presale#Crypto

Free Airdrop News 🔥🔥🔥

@free_airdrop_nn · Post #1162 · 29.09.2025 г., 16:38

We’ve refreshed the MetaGram presale page! New swap-style UI = faster, clearer, mobile-friendly buying. 🚀 Don’t miss the Presale & Airdrop 💎 0.001 BNB → 50 $MGR (airdrop) ⚡️ 0.01 BNB → 500 $MGR 🤝 Referrals: +50% $MGR & +50% BNB 🔥 Listing price: $0.0519 / MGR 👉https://metagram.digital/airdrop #MetaGram#BNB#Presale#Crypto

Airdrop Market Pro

@airdrop_market_pro · Post #1382 · 28.09.2025 г., 20:49

⏳ Only 30 days left until presale & airdrop close — don’t miss your chance! 🚀 MetaGram — Airdrop & Earn Instant BNB! 💎⚡️ 🎁 Airdrop: 5️⃣0️⃣ $MGR for just 0.001 BNB (1 wallet = 1 claim) 💰 Presale: 0.01 BNB → 5️⃣0️⃣0️⃣ $MGR (delivered instantly) 🤝 Referral Bonus: Get ➕5️⃣0️⃣ $MGR and ➕5️⃣0️⃣% BNB from every friend’s presale buy 🎉 Airdrop referrals: ➕2️⃣5️⃣ $MGR for each invite 📈 Listing Price: 1 $MGR = 💵0.051 💦 Join now: 👉@MetagramAirdropbot 🔥 Don’t wait — BNB rewards are already live! #MetaGram#MGR#BNB#Crypto#BSC#Airdrop#Presale

NFT & Airdrop News

@airdrop_nft1 · Post #1378 · 28.09.2025 г., 20:49

⏳ Only 30 days left until presale & airdrop close — don’t miss your chance! 🚀 MetaGram — Airdrop & Earn Instant BNB! 💎⚡️ 🎁 Airdrop: 5️⃣0️⃣ $MGR for just 0.001 BNB (1 wallet = 1 claim) 💰 Presale: 0.01 BNB → 5️⃣0️⃣0️⃣ $MGR (delivered instantly) 🤝 Referral Bonus: Get ➕5️⃣0️⃣ $MGR and ➕5️⃣0️⃣% BNB from every friend’s presale buy 🎉 Airdrop referrals: ➕2️⃣5️⃣ $MGR for each invite 📈 Listing Price: 1 $MGR = 💵0.051 💦 Join now: 👉@MetagramAirdropbot 🔥 Don’t wait — BNB rewards are already live! #MetaGram#MGR#BNB#Crypto#BSC#Airdrop#Presale

Airdrop Market Pro

@airdrop_market_pro · Post #1394 · 20.10.2025 г., 10:23

🔥 MetaGram: MGR Staking is LIVE Stake your $MGR and earn up to 80% APR. • Flexible lock terms: 7–365 days • 0% platform fees while staking • Trading pair: MGR/BNB (details soon) 👉Start now 👉👉👉👉👉👉👉👉 👉https://metagram.digital/staking #MetaGram#MGR#DeFi#BSC#Staking#CryptoEarnings

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