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

Резултати

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

Пребарај: #fxs

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

@proanalysistrader · Post #28380 · 09.01.2025 г., 14:08

#FXS/USDT analysis : #FXS has broken below the 200 EMA and the support zone. It is advisable to wait for a price retest of this zone for a potential short entry, as the price is anticipated to decline further, targeting lower levels. TF : 4h Entry : $3.455 Target : $2.400 SL : $3.945

Hashtags

Pro Analysis

@proanalysistrader · Post #28320 · 07.12.2024 г., 02:39

#FXS/USDT analysis : #FXS has successfully broken out and retested the swing high resistance following the breakout of the trendline in an established uptrend. The price is expected to sustain its bullish momentum and aim for previous highs. TF : 30min Entry : $4.762 Target : $5.080 SL : $4.526

Hashtags

Pro Analysis

@proanalysistrader · Post #28107 · 02.11.2024 г., 12:08

#FXS/USDT analysis : #FXS is currently in a downtrend and is expected to maintain its bearish momentum. For a short entry, wait for the price to break the current support zone, entering on a break below the $1.814 level. The previous lows will serve as target levels. TF : 15min Entry : $1.814 Target : $1.797 SL : $1.826

Hashtags

Pro Analysis

@proanalysistrader · Post #27911 · 07.09.2024 г., 16:20

#FXS/USDT analysis : #FXS is in a downtrend, forming lower lows (LLs) and lower highs (LHs) structure. The price is currently trading in the resistance zone near the 200 EMS. It is expected to be rejected from that area and continue its bearish momentum. TF : 30min Entry : $1.734 Target : $1.651 SL : $1.792

Hashtags

American Crypto©

@americancryptotrading · Post #27455 · 30.11.2025 г., 11:39

🇺🇸#FXS/USDT is trading near the lowerborder of the fallingwedge formation on the weekly chart💁‍♂️ A great moment to accumulate📈 American Crypto©

Hashtags

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