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

Резултати

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

Пребарај: #soneium

当前筛选 #soneium清除筛选
Airdrop Gold : Crypto Airdrop

@airdropgoldchannel · Post #157905 · 30.01.2025 г., 17:50

💥Simple guide on Soneium Galxe quest ✅L2 By Sony 💿 💯FREE 👇Steps 🔗https://app.galxe.com/quest/Soneium/ ✅Complete social task ✅Go to second quest page ✅Complete social task ✅Mint first day NFT ✅Mint daily NFTs ✅Claim points 💥Done #Soneium

Hashtags

TokenPocket

@tokenpocket_channel · Post #1534 · 14.01.2025 г., 09:10

💿 Soneium is now live on TokenPocket! #Soneium is a Layer 2 blockchain that empowers creators, fans, and communities to protect their rights, connect globally, and build an open internet that transcends boundaries. 💙Get started to easily create, import, and sync your #Soneium wallet on TokenPocket! 👉https://tokenpocket.pro

Hashtags

Venture Village Wall 🦄

@venturevillagewall · Post #3871 · 14.01.2025 г., 07:00

Crypto Funds Struggle Compared to Bitcoin OKX's founder Star claims no crypto fund has outperformed Bitcoin over the last decade, predicting a 100x growth for the industry. He acknowledged feedback on OKB's lack of use cases and poor listings. A new secret business line for OKX is set to launch in February. In other news, Ethereum spot ETFs saw a net outflow of $39.432 million, while Bitcoin ETFs faced a larger outflow of $284 million. Notably, BlackRock's ETHA and IBIT ETFs saw significant inflows. Read more about OKX's updates here, Ethereum's ETF activity here, and Bitcoin's ETF activity here. #OKX#Bitcoin#Ethereum#Crypto#ETFs#BlackRock#OKB#NFTs#Web3#DeFi#Soneium#S.BLOX #Blockchain#Investing#Finance#BitcoinETF#EthereumETF#VC#AI

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