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

Резултати

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

Пребарај: #usd0

当前筛选 #usd0清除筛选
Venture Village Wall 🦄

@venturevillagewall · Post #3705 · 24.12.2024 г., 16:00

Binance and Kraken Lead $10M Funding 🐋 Binance and Kraken have spearheaded a $10 million Series A funding round for the rapidly growing stablecoin issuer, Usual, which has launched the USD0 stablecoin backed by RWA assets from BlackRock, Ondo, and Hashnote. With a market cap of $1.5 billion, Usual USD features unique revenue sharing and protocol participation rights for users through its native USUAL token. Recently, Usual also partnered with Ethena, adding USD0 to enhance liquidity in USDtb reserves. Read more about the funding here: Wu Blockchain News #Funding#USD0#Usual#Stablecoins#Kraken#Binance#Blockchain#Liquidity #Funding#USD0#Usual#Stablecoins#Kraken#Binance#Blockchain#Liquidity

Venture Village Wall 🦄

@venturevillagewall · Post #3766 · 01.01.2025 г., 10:00

Syria Moves to Legalize Bitcoin The Syrian transitional government proposes legalizing Bitcoin to combat inflation and attract investments. Plans include facilitating Bitcoin mining and integrating encrypted payment functions in banks. More details: Wu Blockchain News. In related news, a significant sell-off of the Usual protocol's USD0 was triggered by a whale, briefly causing it to dip to $0.99 before re-pegging to $1. Read more: Wu Blockchain News #Bitcoin#Syria#Crypto#Investment#EconomicRecovery#Mining#Regulation#Finance#USD0#WhaleTrade#Inflation#PaymentIntegration#Blockchain#Tech#Markets#Trends #2024

Crypto Headlines

@market_headlines · Post #28171 · 03.04.2026 г., 11:00

#ончейн#рейтинг 🐳Santiment: ТОП-10 токенов по росту активности китов за последнюю неделю. 1. Cronos #CRO 2. Dai (на Polygon) #DAI 3. Usual USD #USD0 4. World Liberty Financial USD #USD1 5. Maker #MKR 6. Dai (на BNB) #DAI 7. UNUS SED LEO #LEO 8. Rain #RAIN 9. Render #RENDER 10. GateToken #GT Crypto Headlines