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

Резултати

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

Пребарај: #iotx

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

@proanalysistrader · Post #28482 · 19.02.2025 г., 16:41

#IOTX/USDT analysis : #IOTX is currently retracing towards the 200 EMA. The price is anticipated to retest the 200 EMA before continuing its bearish momentum. The current level presents a good opportunity for a long entry, as the 200 EMA is expected to be tested. TF : 1h Entry : $0.01860 Target : $0.01973 SL : $0.01790

Hashtags

Pro Analysis

@proanalysistrader · Post #28276 · 27.11.2024 г., 14:26

#IOTX/USDT analysis : #IOTX is currently bouncing back from the trendline and the 200-period exponential moving average (EMA). This price action suggests a potential upward movement, with expectations to test previous swing high levels. The confluence of the trendline and the 200 EMA provides a strong support area, indicating a bullish outlook for IOTX in the near term. TF : 4H Entry : $0.04435 Target : $0.05164 SL : $0.04042

Hashtags

Crypto Headlines

@market_headlines · Post #27920 · 24.03.2026 г., 07:59

🚀#IOTX +22% Триггер: Южнокорейские биржи Upbit, Bithumb и Coinone передумали делистить токен. Cryptо Headlines

Hashtags

Pro Analysis

@proanalysistrader · Post #27839 · 14.08.2024 г., 15:01

#IOTX/USDT analysis : #IOTX is currently consolidating sideways near the resistance zone. It is expected to continue its bearish momentum and test the previous swing low. TF : 2H Entry : $0.0332 Target : $0.0284 SL : $0.0358

Hashtags

Pro Analysis

@proanalysistrader · Post #27720 · 01.07.2024 г., 16:05

#IOTX/USDT analysis - #IOTX be currently rejecting from the rejection zone after forming a lower low. It be expected to decline from there and be testing the previous low. A stop loss will be placed above the rejection zone for risk management. TF : 4h Entry : $0.0395 Target : $0.0372 SL : $0.0409

Hashtags

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