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

Резултати

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

Пребарај: #financetechnology

当前筛选 #financetechnology清除筛选
Crypto M - Crypto News

@CryptoM · Post #64464 · 09.04.2026 г., 01:17

🚀 CZ: Crypto vs Traditional Finance Is a False Divide — 'It's Just a New Technology for Finance' Speaking on The Wolf of All Streets Podcast, Binance founder Changpeng Zhao (CZ) revealed that he shared his memoir Freedom of Money with BlackRock CEO Larry Fink and obtained a quote from him, praising Fink as an example of someone who publicly changed his mind on Bitcoin and pushed it hard afterwards. CZ said he views the framing of crypto versus traditional finance as a false dichotomy — crypto is simply a new technology for finance, and convergence between the two is inevitable, with tokenization of real-world assets as a key driver. On access, CZ argued that any person anywhere in the world should be able to buy any listed stock, calling current restrictions an anomaly that blockchain can help resolve. CZ said the "72 principles" attributed to him online were counted by a Chinese KOL on X, not by him; he removed numbered headings intentionally. He said the principles blog began after a meeting with Ray Dalio in 2021 or 2022, during which Dalio encouraged him to write down his decision-making principles, and it is included as an appendix in Freedom of Money. #Crypto#TraditionalFinance#Blockchain#Tokenization#FinanceTechnology#GlobalFinance#Binance#CZ#LarryFink#RayDalio#BNB#BTC

Venture Village Wall 🦄

@venturevillagewall · Post #4084 · 06.02.2025 г., 16:00

Ondo Finance Launches Layer 1 Blockchain Ondo Finance has officially unveiled the Ondo Chain, a new Layer 1 blockchain designed to facilitate financial markets at an institutional level. This initiative aims to enhance the tokenization of real-world assets, leveraging Blockchain technology to streamline future financial transactions. More details available here. #OndoFinance#Blockchain#RWA#Finance#Crypto#DeFi#InstitutionalFinance#Tokenization#RealWorldAssets#Layer1#CryptoNews#USDC#Innovation#TechNews#Investment#MarketUpdates#Tokenomics#FinanceTechnology#FinancialMarkets#Community