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

Резултати

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

Пребарај: #cryptotrading

当前筛选 #cryptotrading清除筛选

Live Crypto News Today — Bitcoin, Ethereum & Altcoins (February 16, 2026) https://www.fxpremiere.com/live-crypto-news-today-bitcoin-ethereum-altcoins-february-16-2026/#crypto#cryptocurrency#cryptonews#cryptotrading FxPremiere Telegram Alerts

🟥 🟥 🟥GOYIM COIN – SOLANA GEM ALERT 🚀 📈 Strong Pump Ongoing | Heavy Volume Flow 🚀 Early buyers are already winning — next leg loading… 🔹 Chain: Solana 📈 Live on DexScreener: https://dexscreener.com/solana/ASCSDmpkbXDNRiPRKGAPiLU4Kukc6P8vgNBtNhGw3Hnf ✔️ Contract: 9S8edqWxoWz5LYLnxWUmWBJnePg35WfdYQp7HQkUpump 🐋Strong buying pressure • Healthy volume inflow • Meme narrative + active community 🚀 Official Links: 🐦Twitter (X): https://x.com/goyimcoinsol 🌎 Website: https://goyim.life/ #Solana#LowCap#CryptoTrading

Propheta Indicator Signals

@propheta_indicator · Post #23074 · 19.11.2025 г., 17:57

👆 Propheta living up to its name yet again 🔮 Reached 9th TP in the VIP PRO channel! That's why we call it the "Money Printer" 💴💷💵ACCESS TO MANUAL TRADING for 70usdt/month 👉 Looking at those reports and can't believe what you're seing? Go to our reports channel and audit us! @propheta_reports Register and get bonuses up to $6,000 Binance | OKX | ByBit👈🏻click! #cryptotrading#autotrading#cryptomarket

Propheta Indicator Signals

@propheta_indicator · Post #22867 · 07.10.2025 г., 12:13

Reached 9th TP in the VIP HTL channel! Easy $207 with a 5% entry and a $1000 deposit! VIPs getting filthy rich by the day ☺️🤑🤑ACCESS TO MANUAL TRADING for 70usdt/month 👉 Join us and earn big! Start here: t.me/ProphetaAdmin_bot Register and get bonuses up to $6,000 Binance | OKX | ByBit👈🏻click! #cryptobot#cryptotrading#eth

123•••10•••202122
ПретходнаСтраница 1 од 22Следна