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

Пребарај: #cryptotransactions

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

@CryptoM · Post #65069 · 10.04.2026 г., 18:29

🚀 Mempool Space Invaders Offers Satoshi Rewards for High Scores Mempool Space Invaders, a unique game utilizing real-time Bitcoin mempool transactions as targets, is offering players a reward of 10,000 satoshis for achieving a score of 10,000 BTC. According to NS3.AI, the game's creator mentioned that players could expedite reaching the target score by sending 10,000 BTC to themselves. This innovative approach combines gaming with cryptocurrency transactions, providing an engaging experience for Bitcoin enthusiasts. #MempoolSpaceInvaders#SatoshiRewards#Bitcoin#CryptoGaming#BTC#NS3AI#GamingWithCrypto#BitcoinMempool#CryptoTransactions

Venture Village Wall 🦄

@venturevillagewall · Post #3879 · 15.01.2025 г., 04:00

Trump Family Crypto Project Moves Millions The Trump family crypto project, World Liberty, executed a significant transaction today: exchanging 103.1493 WBTC for 3,075.198 ETH (approx. $9.9M) and 16.6199 WBTC for 1.7M USDT via Cow Protocol. Additionally, 11,917.635 ETH (valued around $38.4M) was transferred to Coinbase Prime. Separately, $XRP has crossed a market cap of $155 billion. Read more here. #Trump#Crypto#WBTC#ETH#USDT#Coinbase#XRP#MarketCap#Blockchain#DigitalAssets#Investment#Finance#DeFi#CowProtocol#WorldLiberty#CryptoMarket#Altcoins#TokenExchange#CryptoTransactions#VC

Venture Village Wall 🦄

@venturevillagewall · Post #3870 · 14.01.2025 г., 04:00

Sony Launches Blockchain Platform Soneium Sony's public blockchain platform, *Soneium*, has officially launched on the mainnet. This initiative aims to enhance its technology offerings in the blockchain space. Read more here. In a historic move, Italy's largest bank, *Intesa Sanpaolo*, has purchased 11 bitcoins valued at around €1 million, marking the first direct crypto transaction by a financial institution in Italy. Details can be found here. FTX/Alameda has redeemed and transferred 182,421 SOL (approx. $32.35M) today, raising the total since last November to 4.445M SOL (approx. $516.88M). The staked address currently holds 6.47 million SOL (approx. $1.18B). More information here. The US Court of Appeals ruled in favor of *Coinbase* in its case against the SEC, deeming the SEC's denial of rulemaking as “arbitrary and capricious.” This case revolves around establishing rules for digitally native asset securities. For further reading, click here. #Sony#Blockchain#Soneium#Bitcoin#ECB#Italy#IntesaSanpaolo#CryptoTransactions#FTX#SOL#Coinbase#SEC#DeFi#DigitalAssets#Cryptocurrency#Finance#Investing#VentureCapital#CryptoNews#CryptoMarket