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

Резултати

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

Пребарај: #singsingtycoon

当前筛选 #singsingtycoon清除筛选
SingSing Announcement

@singsingchannel · Post #798 · 12.09.2024 г., 14:31

🚨 Lucky Box Session 2: SOLD OUT 🚨 Big thanks to everyone who joined! 🎉 Now, get ready for the new game launch and don’t forget to claim your NFTs as soon as the game goes live 🚀 Stay tuned for more exciting updates! 🎁 #SingSingTycoon#LuckyBox

SingSing Announcement

@singsingchannel · Post #862 · 30.09.2024 г., 13:05

🚀 SingSing Top Referral Event 🚀 To celebrate the launch of the new SingSing Tycoon game, we're hosting a special event with a total prize pool of 160,000 $KARA! 🔥 🏆 Categories: Top 10 Referrers with most Referees - 95,000 $KARA 🥇 1st: 30K $KARA 🥈 2nd: 20K $KARA 🥉 3rd: 10K $KARA 🏅 4th-10th: 5K $KARA Top 5 Referrers with highest TON Commission - 65,000 $KARA 🥇 1st: 20K $KARA 🥈 2nd: 15K $KARA 🏅 3rd-5th: 10K $KARA 📅 Duration: Sep 30, 13:00 UTC - Oct 30, 23:59 UTC Invite & Earn BIG! 💸 #SingSingTycoon#KARA 🎤Announcement | Chat | X (Twitter) | Website | Game

SingSing Announcement

@singsingchannel · Post #1047 · 23.11.2024 г., 02:52

🎉 Let’s recap the 10 Lucky Stakers who snagged the first 10 TON in the 100 TON Daily Tycoon Launchpool! 1️⃣ CebuanoKing 🔵 ONUS BITS $X💠 2️⃣ Süleyman 3️⃣@Click_Mining 4️⃣ Arthur 5️⃣ Modzilla 🐔🐈‍⬛🎤 Firefox 6️⃣ SanMoTraz 7️⃣ Tuấn Anh 🇻🇳🐾 8️⃣ Em 🐔🍅🎤 C ^^ 9️⃣ Pham Minh Nhan 🔟 Xaumarket 🔥 9 more days to go! Keep staking for your chance to win big 👉https://t.me/SingSing_TG_bot/app 👉#SingSingTycoon#TON#Launchpool

SingSing Announcement

@singsingchannel · Post #886 · 09.10.2024 г., 08:02

⚡️ Game Adjustment Alert ⚡️ Starting from floor 2, rooms without NFT will see a 50% decrease in earnings! 👀 Application time: From 13:00 UTC - Oct 9 You know what to do! Don’t let those NFTs sit idle in the Vault—equip them NOW for max earnings 💥🎤 #SingSingTycoon#NFTPower 🎤Announcement | Chat | X (Twitter) | Website | Game

SingSing Announcement

@singsingchannel · Post #856 · 28.09.2024 г., 18:22

🎤 Ready to take your karaoke empire to the next level? With Karaoke Box NFT and KTV NFT, the path to becoming the ultimate tycoon is within reach! 💥 Karaoke Box NFT is your ticket to faster earnings! The rarer the box, the more your earning speed skyrockets: Common ➡️ x1.5 earning speed Uncommon ➡️ x2 earning speed Rare ➡️ x4 earning speed Epic ➡️ x6 earning speed Legendary ➡️ x8 earning speed 🏢 Meanwhile, the KTV NFT is key to unlocking more floors, allowing your karaoke chain to expand beyond limits: Common ➡️ +1 floor Uncommon ➡️ +3 floors Rare ➡️ +5 floors Epic ➡️ +10 floors Legendary ➡️ +15 floors ✨ The rarer the NFT, the bigger the rewards! Time to upgrade and watch your karaoke business thrive like never before! 🚀 Check out how to leverage your NFTs here: https://t.me/singsingchannel/831 #SingSingTycoon#NFTPower 🎤Announcement | Chat | X (Twitter) | Website | Game

SingSing Announcement

@singsingchannel · Post #873 · 03.10.2024 г., 13:45

🚀 How to List Your NFT on SingSing Tycoon NFT Marketplace 🚀 1️⃣ Activate 2FA first! (Required for all NFT Marketplace transactions) (https://t.me/singsingchannel/869) 2️⃣ Tap the NFT Trade icon at the bottom-right to enter the Marketplace. 3️⃣ Click the Options Menu (top-right) and select 'List Your NFT.' 4️⃣ Choose the NFT you want to list. 5️⃣ Set your price in TON & hit 'List NFT.' Once listed, check 'My Listed' to view your NFTs. Start listing and trading now! 💎🛒 #SingSingTycoon#NFTMarketplace#Web3 🎤Announcement | Chat | X (Twitter) | Website | Game

SingSing Announcement

@singsingchannel · Post #874 · 03.10.2024 г., 14:57

🎤 Add this emoji to your Telegram name & get free $KARA! 🎉 How to claim: 1️⃣ Copy this emoji: 🎤 2️⃣ Open Telegram -> Settings -> My Account -> Name 3️⃣ Paste that adorable 🎤 next to your name 4️⃣ Complete the task in the SingSing Tycoon app 👉Claim your $KARA💰 Easy peasy! Go claim your rewards now! 🎉 #SingSingTycoon#FreeKARA#Web3 🎤Announcement | Chat | X (Twitter) | Website | Game

SingSing Announcement

@singsingchannel · Post #897 · 14.10.2024 г., 13:00

🚨 Oct 14 Sale is LIVE NOW! 🚨 🎁 30 Lucky Boxes – 400 RUBY each Unbox and receive random KTV NFT or Karaoke Box NFT 🎤 🔗Purchase Link - https://t.me/SingSing_TG_bot/app?startapp=_marketplace #SingSingTycoon#LuckyBox#KaraBox 🎤Announcement | Chat | X (Twitter) | Website | Game

SingSing Announcement

@singsingchannel · Post #888 · 09.10.2024 г., 13:00

🚨 Oct 9 Sale is LIVE NOW! 🚨 🎁 40 Lucky Boxes – 400 RUBY each Unbox and receive random KTV NFT or Karaoke Box NFT 🎤 🔗Purchase Link - https://t.me/SingSing_TG_bot/app?startapp=_marketplace #SingSingTycoon#LuckyBox#KaraBox 🎤Announcement | Chat | X (Twitter) | Website | Game

SingSing Announcement

@singsingchannel · Post #881 · 07.10.2024 г., 13:00

🚨 Oct 7 Sale is LIVE NOW! 🚨 🎁 30 Lucky Boxes – 400 RUBY each 📦 20 Kara Boxes – 300 RUBY each 🔗Purchase Link - https://t.me/SingSing_TG_bot/app?startapp=_marketplace #SingSingTycoon#LuckyBox#KaraBox 🎤Announcement | Chat | X (Twitter) | Website | Game

123•••56
ПретходнаСтраница 1 од 6Следна