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

Резултати

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

Пребарај: #mkr

当前筛选 #mkr清除筛选
Pro Analysis

@proanalysistrader · Post #28474 · 16.02.2025 г., 16:50

#MKR/USDT analysis : #MKR is currently in a downtrend. It is advisable to wait for the price to retrace and test the resistance zone for a short entry. The price is expected to resume its bearish momentum and test lower levels. TF : 4H Entry : $1,074 Target : $778 SL : $1,209

Hashtags

Pro Analysis

@proanalysistrader · Post #28418 · 25.01.2025 г., 13:08

#MKR/USDT analysis : #MKR is in a downtrend, forming lower lows (LLs) and lower highs (LHs). The price is anticipated to continue its bearish momentum and test lower levels. It is recommended to wait for a pullback for a short entry. TF : 2h Entry : $1,283 Target : $1,006 SL : $1,426

Hashtags

Pro Analysis

@proanalysistrader · Post #27845 · 16.08.2024 г., 11:54

#MKR/USDT analysis : #MKR is currently consolidating in a channel. The higher timeframe direction shows bearish sentiment, hinting at a possible breakout from the channel to keep moving downwards to lower levels. Waiting for a channel break and the $1,884 level before considering a short entry is recommended. TF : 2H Entry : $1,884 Target : $1,576 SL : $2,045

Hashtags

American Crypto©

@americancryptotrading · Post #27134 · 27.01.2025 г., 19:04

🇺🇸#MKR/USDT has retested the s/rzone on the weekly timeframe👀 Time to rise after bounce🚀 American Crypto©

Hashtags

Coinlegs Cryptocurrency Signals

@coinlegs · Post #10216 · 19.04.2024 г., 08:08

#MKR | Failure Swing detected by CoinLegs Algorithm 😎 A quick and risky position can be opened from the neck area. Personally, I would be a bit more cautious and wait for the price to come down and rise from there. Dyor, NFA. www.coinlegs.com

Hashtags

Crypto

@signal_bitcoins · Post #1885 · 17.12.2023 г., 10:01

💰#MKR pullback done,now we are waiting for a bullish momentum from the Green zone,pump it to the moon 🚀 ❄️@signals_bitcoin_crypto❄️ ❄️@Shadow_support0o❄️

Hashtags

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