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

Резултати

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

Пребарај: #priceincrease

当前筛选 #priceincrease清除筛选
Crypto M - Crypto News

@CryptoM · Post #64937 · 10.04.2026 г., 11:02

🚀 Ethereum(ETH) Surpasses 2,200 USDT with a 0.38% Increase in 24 Hours On Apr 10, 2026, 11:02 AM(UTC). According to Binance Market Data, Ethereum has crossed the 2,200 USDT benchmark and is now trading at 2,200.620117 USDT, with a narrowed 0.38% increase in 24 hours. #Ethereum#ETH#Binance#cryptocurrency#USDT#marketdata#priceincrease

Crypto M - Crypto News

@CryptoM · Post #64813 · 10.04.2026 г., 01:37

🚀 Ethereum(ETH) Surpasses 2,200 USDT with a 1.22% Increase in 24 Hours On Apr 10, 2026, 01:37 AM(UTC). According to Binance Market Data, Ethereum has crossed the 2,200 USDT benchmark and is now trading at 2,201.939941 USDT, with a narrowed 1.22% increase in 24 hours. #Ethereum#ETH#USDT#Binance#cryptocurrency#marketdata#priceincrease

Crypto M - Crypto News

@CryptoM · Post #64938 · 10.04.2026 г., 11:04

🚀 Bitcoin(BTC) Surpasses 72,000 USDT with a 0.99% Increase in 24 Hours On Apr 10, 2026, 11:04 AM(UTC). According to Binance Market Data, Bitcoin has crossed the 72,000 USDT benchmark and is now trading at 72,013.742188 USDT, with a narrowed 0.99% increase in 24 hours. #Bitcoin#BTC#USDT#Cryptocurrency#Binance#CryptoNews#PriceIncrease#MarketData

Crypto M - Crypto News

@CryptoM · Post #64805 · 10.04.2026 г., 00:52

🚀 Bitcoin(BTC) Surpasses 72,000 USDT with a 1.86% Increase in 24 Hours On Apr 10, 2026, 00:52 AM(UTC). According to Binance Market Data, Bitcoin has crossed the 72,000 USDT benchmark and is now trading at 72,000 USDT, with a narrowed 1.86% increase in 24 hours. #Bitcoin#BTC#USDT#Binance#MarketData#Crypto#PriceIncrease#72k

Crypto M - Crypto News

@CryptoM · Post #64718 · 09.04.2026 г., 15:44

🚀 Bitcoin Surpasses 72,000 USDT with Daily Increase Bitcoin has exceeded the 72,000 USDT mark, currently trading at 72,010.08 USDT, reflecting a daily increase of 1.33%. According to Foresight News, this development was observed through Bitget's market data. #Bitcoin#USDT#Crypto#Cryptocurrency#Trading#Bitget#MarketUpdate#PriceIncrease#BTC

Crypto M - Crypto News

@CryptoM · Post #64860 · 10.04.2026 г., 05:07

🚀 XRP Rises to $1.35 Amid Strong Trading Volume XRP experienced a price increase, reaching $1.35 after surpassing the $1.34 mark on strong trading volume. According to NS3.AI, the upward movement paused below $1.36, and XRP continues to be part of a broader downtrend. There is no clear catalyst identified for this recovery. #XRP#cryptocurrency#tradingvolume#priceincrease#downtrend#NS3AI

Crypto M - Crypto News

@CryptoM · Post #65123 · 11.04.2026 г., 06:04

🚀 RAVE Experiences Significant Price Surge RAVE has recently experienced a notable increase in its market value, surpassing $2.1 and currently trading at $2.09. According to Odaily, the cryptocurrency has seen a daily increase of over 100% and a three-day surge exceeding 700%. #RAVE#cryptocurrency#priceincrease#marketvalue#surge

Crypto M - Crypto News

@CryptoM · Post #65193 · 11.04.2026 г., 18:37

🚀 Ethereum(ETH) Surpasses 2,300 USDT with a 2.50% Increase in 24 Hours On Apr 11, 2026, 18:37 PM(UTC). According to Binance Market Data, Ethereum has crossed the 2,300 USDT benchmark and is now trading at 2,301.360107 USDT, with a narrowed 2.50% increase in 24 hours. #Ethereum#ETH#USDT#Binance#cryptocurrency#marketdata#priceincrease#cryptomarket#24hours

Crypto M - Crypto News

@CryptoM · Post #65080 · 10.04.2026 г., 20:31

🚀 BNB Surpasses 610 USDT with a 0.22% Increase in 24 Hours On Apr 10, 2026, 20:31 PM(UTC). According to Binance Market Data, BNB has crossed the 610 USDT benchmark and is now trading at 610.109985 USDT, with a narrowed 0.22% increase in 24 hours. #BNB#610USDT#cryptocurrency#Binance#marketdata#priceincrease#24hourchange

Crypto M - Crypto News

@CryptoM · Post #64763 · 09.04.2026 г., 20:15

🚀 Ether Rises Over 6% as Undervaluation Signals Potential Retest of Higher Levels Ether experienced a 6.33% increase, surpassing $2,150, with indicators suggesting a potential retest of the $2,400–$2,500 range. According to NS3.AI, the Capriole Macro Index Oscillator registered a reading of -2.42, indicating that Ether is in a rare undervaluation zone. This development has sparked interest among investors, who are closely monitoring the cryptocurrency for further movements. #Ether#Crypto#Ethereum#Undervaluation#PriceIncrease#Investment#CryptoTrading#NS3AI#ETH

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