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

Резултати

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

Пребарај: #profits

当前筛选 #profits清除筛选
Crypto GALAXY

@crypto_galaxy_signals · Post #491 · 18.02.2024 г., 12:39

Boost your #crypto#profits effortlessly with our VIP-Channel. Join now for expert signals and start winning big in the crypto market! 💬Contact & VIP Support

Daily Channels

@dailychannels · Post #6022 · 22.04.2025 г., 01:00

Channel: Bitcoin leverage signals Members: ~9.42K 💢 Username: @bitcoinleverage Description: # BTC USDT leverage signals. Free advice, crypto advice and more. No strings attached. Fair channel. Bitcoin advice, bitcoin trading, trading tips, leverage trading, cryptotrading, stocks. 🏷 Tags: #crypto_fx_trading #bitcoin#crypto#advice#trading#profits https://telegramchannels.me/channels/bitcoinleverage

Daily Channels

@dailychannels · Post #6584 · 02.01.2026 г., 01:01

Channel: Profit Wave FX Members: ~16.9K 💢 Username: @profitwavefxs Description: Click the 3 dot above (open in browser) then it will work. Signal with reason 2025 is the year 🏷 Tags: #crypto_fx_trading #gold#profits#xauusd#trade_wave#signals https://telegramchannels.me/channels/profitwavefxs

Bounty Hunters 💎

@trustedairdropsss · Post #2697 · 07.06.2025 г., 04:49

🚀 Booked ₹1.37+ Lakh Profit! 💰 Another great day in the markets with smart entries & exits. 📈 Check out the power of precision trading! 🔥 🧠 Join my private trading community for real-time insights, setups, and mentorship. Whether you're new or experienced — you’ll level up fast. 👇 Click to join now 🔗https://t.me/+7emcw1k0H_U4ZDg9 📊 Stay ahead, trade smart. 💯 #BankNifty#OptionsTrading#StockMarketIndia#TradeLab#Profits

Bounty Hunters 💎

@trustedairdropsss · Post #2696 · 06.06.2025 г., 14:07

🚀 Booked ₹1.37+ Lakh Profit! 💰 Another great day in the markets with smart entries & exits. 📈 Check out the power of precision trading! 🔥 🧠 Join my private trading community for real-time insights, setups, and mentorship. Whether you're new or experienced — you’ll level up fast. 👇 Click to join now 🔗https://t.me/+7emcw1k0H_U4ZDg9 📊 Stay ahead, trade smart. 💯 #BankNifty#OptionsTrading#StockMarketIndia#TradeLab#Profits

Bounty Hunters 💎

@trustedairdropsss · Post #2695 · 06.06.2025 г., 13:59

🚀 Booked ₹1.37+ Lakh Profit! 💰 Another great day in the markets with smart entries & exits. 📈 Check out the power of precision trading! 🔥 🧠 Join my private trading community for real-time insights, setups, and mentorship. Whether you're new or experienced — you’ll level up fast. 👇 Click to join now 🔗https://t.me/bankniftygo 📊 Stay ahead, trade smart. 💯 #BankNifty#OptionsTrading#StockMarketIndia#TradeLab#Profits

Venture Village Wall 🦄

@venturevillagewall · Post #3941 · 21.01.2025 г., 16:00

NFT Investors Question Trump's Impact A recent survey by NFT Evening revealed that 42% of respondents who bought Official Trump (TRUMP) and Official Melania (MELANIA) NFTs were first-time crypto users. While 81% of TRUMP investors and 86% of MELANIA investors reported profits as of yesterday, nearly 75% believe Trump's NFT launch is harmful to the crypto market. Additionally, 98% chose not to invest further, with 55% asserting that Trump and Melania are attempting to manipulate the market. Read more. #NFT#Trump#Crypto#Investors#Market#MELANIA#Blockchain#Survey#Profits#Regulations#Manipulation#Politics#Investment#Trends#US#KYC#Web3#AI#VC

Venture Village Wall 🦄

@venturevillagewall · Post #3911 · 18.01.2025 г., 10:00

Trump's Meme Coin Launches Amid Trading Frenzy 🚀 Bybit unveils TRUMPUSDT perpetual swap today! Trading also starts on Gate and Bitget for the new meme token TRUMP, which has surged in price in sync with Trump's upcoming inauguration. A trader scored $29.8M in profits from a $1.09M USDC investment, purchasing nearly 6 million TRUMP tokens. Learn more about the frenzy: Forklog News #TrumpCoin#Solana#Bybit#Gate#Bitget#Trading#Crypto#Memecoin#Investing#USDC#Profits#Market#Finance#News#VC#AI#CEX#SpotTrading#Derivatives#MemeToken