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

Резултати

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

Пребарај: #virtual

当前筛选 #virtual清除筛选
Coin Sonar

@CoinSonar · Post #243871 · 17.04.2026 г., 23:25

#VIRTUAL | Volume spike (USDT PAIR) 59 times the average volume 360.92K USDT traded in 1 min └Buying vol: 301.15K USDT 🟢 Boost score: 7/10 24h Vol: 8.80M USDT (Binance) Price: 0.7456 (-3.8% in 24h)

Hashtags

Coin Sonar

@CoinSonar · Post #243776 · 17.04.2026 г., 16:49

#VIRTUAL | Volume spike (USDT PAIR) 68 times the average volume 417.92K USDT traded in 1 min └Selling vol: 243.99K USDT 🔴 Boost score: 1/10 24h Vol: 8.80M USDT (Binance) Price: 0.7740 (-3.8% in 24h)

Hashtags

Coin Sonar

@CoinSonar · Post #243643 · 17.04.2026 г., 12:46

#VIRTUAL | Volume spike (USDT PAIR) 63 times the average volume 385.97K USDT traded in 1 min └Buying vol: 271.37K USDT 🟢 Boost score: 6/10 24h Vol: 8.80M USDT (Binance) Price: 0.7572 (-3.8% in 24h)

Hashtags

Free Crypto Signals (Profitable Zone)

@btctradingclub · Post #26724 · 06.01.2026 г., 08:33

✅✅ 45% Profit on #VIRTUAL/USDT for our Premium Members on Binance Futures/Bybit/OKX & KuCoin - The trade has been closed in good profit 👁‍🗨Contact @primemod to enter the Premium Group & make daily gains - We are the best here since 5+ years

Hashtags

Alphavave Traders ️️️

@alphavave · Post #2975 · 02.11.2025 г., 02:59

#VIRTUAL has achieved an impressive 4545% profit, marking another big win, no surprise there 🫡 💰A nice 45.5X return from this single Signal 💰$50 would return $3,030 💸 💰$50 would return$2,270 💸 💰$50 would return$1,510 💸 Nobody can match our skills. We've got the strategies, the knowledge, real tools, actionable signals, and proven strategies that deliver the hustle to turn every opportunity into a cash-making machine🤑 We are in the fast lane, leaving the competition eating our dust 💰 If you want daily signals like this, DM me! 👉@Kevindexter✅️

Hashtags

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