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

Резултати

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

Пребарај: #alpha

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

@proanalysistrader · Post #28355 · 24.12.2024 г., 13:46

#ALPHA/USDT analysis : #ALPHA is currently in an uptrend, forming higher highs (HHs) and higher lows (HLs). The price has retraced to a support zone, and a bounce back is anticipated, with expectations to test previous highs. TF : 1D Entry : $0.0870 Target : $0.1340 SL : $0.0674

Hashtags

Pro Analysis

@proanalysistrader · Post #27943 · 18.09.2024 г., 14:26

#ALPHA/USDT analysis : #ALPHA is presently in a downtrend, trading below the 200 EMA. The price is establishing a pattern of lower lows and lower highs. Currently, it encounters resistance near the 200 EMA, indicating a possible continuation of its bearish trend and a retest of previous lows. TF : 4h Entry : $0.0558 Target : $0.0520 SL : $0.0584

Hashtags

American Crypto©

@americancryptotrading · Post #27104 · 01.01.2025 г., 17:54

🇺🇸#ALPHA/USDT is heading towards the descendingtriangle pattern on the weekly timeframe👀 Breakout - Retest - Go🐃 American Crypto©

Hashtags

Coinlegs Cryptocurrency Signals

@coinlegs · Post #9322 · 05.11.2023 г., 13:44

Custom Signal: Combination of 👉 Double Bottom 👉 Bollinger Breakout 👉 Trend Line Breakout We expect the price goes up after double bottom but we can’t trade by using only double bottom pattern. We look for another bullish moves like bollinger or trend line breakout. What if double bottom, Trend Line Breakout and Bollinger Breakout occur for any asset and it’s price hasn’t risen yet Bingo !! #ALPHA did 15% in just 3 hours 👌 Just check the chart, let’s create custom signal

Hashtags

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