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

Резултати

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

Пребарај: #xtz

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

@proanalysistrader · Post #28430 · 28.01.2025 г., 13:50

#XTZ/USDT analysis : #XTZ is in an uptrend and has broken out above the 200 EMA and previous highs. Currently, the price is retesting the previous resistance zone, which has now turned into support. It is anticipated that the price will rebound from this level and resume bullish momentum to test the previous highs. TF : 1D Entry : $1.012 Target : $1.800 SL : $0.783

Hashtags

Pro Analysis

@proanalysistrader · Post #28342 · 15.12.2024 г., 12:33

#XTZ/USDT analysis : #XTZ has broken below the 200 EMA and has retested it. Currently, the price is encountering resistance from the resistance zone, and it is expected to decline from here. A drop is anticipated, potentially leading to a test of previous lows. TF : 2H Entry : $1.420 Target : $1.150 SL : $1.530

Hashtags

Pro Analysis

@proanalysistrader · Post #28023 · 15.10.2024 г., 14:54

#XTZ/USDT analysis : #XTZ has broken out and retested the previous swing high and the 200 EMA. The price is expected to bounce back from this level and test the higher levels. TF : 4H Entry : $0.694 Target : $0.744 SL : $0.661

Hashtags

Pro Analysis

@proanalysistrader · Post #27837 · 13.08.2024 г., 16:39

#XTZ/USDT analysis : #XTZ is again approaching the 200 EMA resistance after facing rejection from there and is expected to continue its bearish momentum once the zone is tested. The previous low will be the target level. TF : 2H Entry : $0.687 Target : $0.591 SL : $0.709

Hashtags

American Crypto©

@americancryptotrading · Post #27528 · 08.02.2026 г., 10:09

🇺🇸#XTZ/USDT is facing the lowerboundary of the fallingwedge formation on the 2W chart👨‍💻 Expecting a price recovery🚀 American Crypto©

Hashtags

American Crypto©

@americancryptotrading · Post #27369 · 09.09.2025 г., 09:42

🇺🇸#XTZ/USDT has retested the s/rzone on the daily chart🔍 The rally is coming🚀 American Crypto©

Hashtags

123•••89
ПретходнаСтраница 1 од 9Следна