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 слични објави

Пребарај: #gsr

当前筛选 #gsr清除筛选
SpotOnChain | Announcement

@spotonchain · Post #671 · 25.01.2024 г., 05:17

Altlayer, the 45th project on #Binance Launchpool, will be listed today, Jan 25, 2024, at 10:00 AM (UTC). Prior to the listing, Alt Layer multisig transferred 40M $ALT to @GSR_io 7 days ago; And so far, #GSR has deposited 15M $ALT into #Binance, #MEXC and #Gateio in the past 15 hours. 👉 GSR address: https://platform.spotonchain.ai/en/platform/profile?address=0xbd513f67ed9bccc8364176e8b97bb93a5030e777

NEWS 鏈新聞-ABMedia

@abmedia_news · Post #24362 · 05.05.2026 г., 03:31

【💰 交易市場|渣打銀行旗下SC Ventures策略投資加密造市商GSR】 #GSR#SCVentures#渣打銀行 SC Ventures 執行長 Alex Manson 宣佈投資 GSR,成為其十年來首位外部股東。 雙方深化 Libeara 平台合作,並預計年內推出 2.5 億美元數位資產基金。銀行巨頭整合造市技術,顯現加密市場加速機構化趨勢。 📍閱讀全文: https://abmedia.io/standard-chartered-investing-gsr 📍 訂閱鏈新聞頻道:https://linktr.ee/abmedia.io

Venture Village Wall 🦄

@venturevillagewall · Post #3758 · 31.12.2024 г., 07:00

2023 Reflections and Initiatives Key takeaways from the past year: Emphasis on founder-side roles, collaborations with dynamic teams, and growth initiatives. Initiated two accelerators: triangle.tg connecting TON to Web3, supporting 11 teams with notable backers like Binance Labs, GSR, and others. Launched Gaming.tg with Anton from Helika.io, focusing on the gaming sector. Significant partnerships emerged, enhancing the value for founders. Currently supporting promising Telegram ecosystem projects, anticipating a return to article writing in 2025. Appreciating the support received and lessons learned. #FounderSide#Web3#TON#Accelerator#Gaming#BinanceLab#GSR#Polychain#DelphiDigital#Blackrock#TriangleTG#GamingTG#Community#Innovations#Telegram#Investments#2023Reflections#CholyLabs#Projects#Support#Partnerships#Leadership