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

Пребарај: #blockchains

当前筛选 #blockchains清除筛选
Telegram & TON NEWS

@all_telegram_ton_news · Post #22617 · 07.01.2026 г., 08:58

The Daily TON (Telegram) 🔥 EVM vs non-EVM ⚫️ Let's expand on the topic "#blockchains in 2026". If you have interacted with DeFi, you have probably heard the terms "EVM-compatible" or "non-EVM" blockchain. This is not just technical jargon, but a fundamental division that determines which applications can run on the network and who will develop them. ⚫️EVM (Ethereum Virtual Machine) is the Ethereum virtual machine that has become the standard in the crypto world. Blockchains like Polygon, BSC, and Avalanche are EVM-compatible. This means that any smart contract or dApp written for Ethereum can be ported to such networks with almost no changes. The main advantage is compatibility and a huge ecosystem: developers, tools, and users are already there. ⚫️Non-EVM blockchains are networks with their own unique architecture. Bitcoin stands apart without smart contracts. Solana, SUI, TON, and others have created their own virtual machines and programming languages. Their goal is not... View original post

Hashtags

djangoproject

@djangoproject · Post #499 · 14.11.2017 г., 16:33

https://pypi.python.org/pypi/hyperledger/0.1.5 #Python#client for #Hyperledger. This work is licensed under the Apache License, Version 2.0. Hyperledger Project is a new Collaborative Project at The Linux Foundation. The technical community is just getting started and will be adding code to the repository in the coming weeks. Check hyperledger.org for more information about joining the mailing lists and participating in the conversations. #Blockchains