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

Пребарај: #megabase

当前筛选 #megabase清除筛选
Crypto Fight || News 🚀

@cryptofightnews · Post #3162 · 16.12.2025 г., 15:37

🔥MegaBase ($MGBS) 🚀The Future of Community-Driven Wealth is Here — MegaBase ($MGBS) is on a bold mission to build real value and empower collective success. We’re not just another crypto project — we’re creating a sustainable ecosystem where the community truly wins. 📨Every $MGBS transaction fuels more than just our token growth, it creates a global impact. 🚨Small percentage of the transaction fees goes to charitable causes chosen by the community.✅ ✅Earn rewards ✅Auto-burn ✅Milestone Giveaway ✅Auto Liquidity ✅Progressive Protection Protocol ✅Ecosystem engineered for Continous Development 📌Ca: 0x481ef7Ff561d9a2a892553ba930A6365f911E0bb 🔥Dex: https://dexscreener.com/base/0xe348135151c3bFF2bcaB2a9F7A571e7214edc6A8 ⬇️ Social links 🔥 Telegram: https://t.me/+IQ696SfodDQwOTEx 🔥 Website: https://megabasecoin.com 🔥 X (Twitter): https://x.com/megabasecoin 🍏🍏🍏🍏 🚀AMA Today with Crypto Panda on Binance Space 🐼🎙 🔜 2:00 PM ET 🎁 Active Launch Giveaway running till 31st December 2025! Join our Telegram for full details or check our X page to participate. #MegaBase#MGBS#CryptoPresale#DeFi#Web3#Blockchain#CommunityWealth#Crypto#Base#Coinbase#Bullrun#Bitcoin#Bullish#Ethereum#DEX#C

⚪️ 🔤 🔤 🔤 🔤 MEGABASE COIN ($MGBS) The Future of Community-Driven Wealth Starts Now 💰Contract Address: 0x481ef7Ff561d9a2a892553ba930A6365f911E0bb MegaBase ($MGBS) is more than a token — it’s a long-term vision built on transparency, innovation, and community empowerment. We are designing a sustainable ecosystem where growth is shared, value is real, and the community always comes first. 🌍✨ 💥 Why MegaBase? Every $MGBS transaction contributes to something bigger than price action — it helps fuel ecosystem growth and real-world impact. 🔥 Core Features 💰 Earn Rewards 🔥 Auto-Burn Mechanism 🎁 Milestone Giveaways 💧 Auto Liquidity 🛡 Progressive Protection Protocol 🔄 Ecosystem Engineered for Continuous Development ❤️ Charity Contributions Selected by the Community A small percentage of each transaction supports charitable causes, ensuring MegaBase creates global impact alongside financial growth. 💎 Community members will have the opportunity to earn rewards as MegaBase reaches key milestones. This giveaway is our way of saying thank you for believing early and building with us. 🔗 Join the MegaBase Movement ✅Telegram: https://t.me/+IQ696SfodDQwOTEx Twitter: www.x.com/megabasecoin ✅Website: https://megabasecoin.com Let’s build together. Let’s grow together. Let’s succeed together. 💪 #MegaBase#MGBS#Cryptolaunch#LaunchGiveaway#DeFi#Web3#Blockchain#CommunityWealth#Crypto#Base#Coinbase#Bullrun#Bitcoin#Ethereum#DEX#CEX#Bullish