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

Резултати

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

Пребарај: #knc

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

@CoinSonar · Post #243789 · 17.04.2026 г., 17:27

#KNC | Volume spike (USDT PAIR) 37 times the average volume 133.05K USDT traded in 15 min └Selling vol: 68.20K USDT 🔴 Boost score: 1/10 24h Vol: 344.44K USDT (Binance) Price: 0.1480 (-0.3% in 24h)

Hashtags

Coin Sonar

@CoinSonar · Post #243719 · 17.04.2026 г., 14:48

#KNC | Volume spike (USDT PAIR) 38 times the average volume 139.91K USDT traded in 15 min └Buying vol: 90.32K USDT 🟢 Boost score: 6/10 24h Vol: 344.44K USDT (Binance) Price: 0.1548 (-0.3% in 24h)

Hashtags

Pro Analysis

@proanalysistrader · Post #28477 · 18.02.2025 г., 13:57

#KNC/USDT analysis : #KNC is retracing towards the 200 EMA, indicating potential upside. The price is respecting the trendline and bouncing back, which suggests a good opportunity for a long entry. Previous highs will serve as target levels. TF : 4H Entry : $0.4198 Target : $0.4582 SL : $0.3939

Hashtags

Pro Analysis

@proanalysistrader · Post #27936 · 15.09.2024 г., 16:40

#KNC/USDT analysis : #KNC is currently in a downtrend, trading below the 200 EMA. The price is forming a pattern of lower lows and lower highs. At present, the price is facing resistance near the 200 EMA, suggesting a potential reversal from this point to maintain its bearish movement and establish a new lower low. TF : 4H Entry : $0.4419 Target : $0.4083 SL : $0.4589

Hashtags

American Crypto©

@americancryptotrading · Post #27385 · 23.09.2025 г., 09:12

🇺🇸#KNC/USDT is attempting to bounce off the supportzone on the weekly chart💁‍♂️ Time to load a bag🐃 American Crypto©

Hashtags

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