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

Резултати

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

Пребарај: #kws

当前筛选 #kws清除筛选
Top Telegram Channels - Europe

@topchannels_europe · Post #808 · 10.05.2026 г., 10:05

👑 Top discounts and deals from AMAZON: ➡️AMAZON In Germany ➡️AMAZON in Spain ➡️AMAZON in France ➡️AMAZON in Italy ➡️AMAZON in United Kingdom ➡️AMAZON in the Netherlands ➡️AMAZON in Belgium ➡️AMAZON in Poland ➡️AMAZON in Sweden ⭐️The best sales & deals online!@BestenDeals #Amazon#kws

Hashtags

Top Telegram Channels - Europe

@topchannels_europe · Post #801 · 04.05.2026 г., 08:47

⭐️Special offer from AMAZON: ➡️Tshirt Women Oversize Shirt Women Tops Summer ➡️https://amzn.to/4w4GoxW 💶 14.99€-> 12.74€ (-15%) ✨Ends in 15 hours ⭐️The Best Offers & Deals in EuropeOnline: ➡️@BestenDeals #Amazon#kws

Hashtags

Top Telegram Channels - Europe

@topchannels_europe · Post #789 · 28.04.2026 г., 08:07

⭐️AMAZON Special Offer: ➡️Women's Blouse 3/4 Sleeve Shirt Elegant V-Neck Tunic Summer Tops ➡️https://amzn.to/4ufgTIH 💶 19.99€ -> 16.99€ (-15%) ✨ 50+ sold/month ⭐️The Best Offers & Deals in EuropeOnline: ➡️@BestenDeals #Amazon#kws

Hashtags

Top Telegram Channels - Europe

@topchannels_europe · Post #764 · 10.04.2026 г., 10:05

👑 Top discounts and deals from AMAZON: ➡️AMAZON In Germany ➡️AMAZON in Spain ➡️AMAZON in France ➡️AMAZON in Italy ➡️AMAZON in United Kingdom ➡️AMAZON in the Netherlands ➡️AMAZON in Belgium ➡️AMAZON in Poland ➡️AMAZON in Sweden ⭐️The best sales & deals online!@BestenDeals #Amazon#kws

Hashtags

Top Telegram Channels - Europe

@topchannels_europe · Post #751 · 01.04.2026 г., 07:54

⭐️Aktionsangebot von AMAZON: ➡️Dubinik® 6 oz Flanellhemd Herren Flanellhemden Herren Langarm Regular Fit Kariert Button Down Warm Freizeit Herren Hemd ➡️https://amzn.to/4bOZE9e 💶 49,99€-> 35,69€ (-29%) ✨ Befristetes Angebot #Amazon#kws

Hashtags

Top Telegram Channels - Europe

@topchannels_europe · Post #717 · 10.03.2026 г., 10:06

👑 Top discounts and deals from AMAZON: ➡️AMAZON In Germany ➡️AMAZON in Spain ➡️AMAZON in France ➡️AMAZON in Italy ➡️AMAZON in United Kingdom ➡️AMAZON in the Netherlands ➡️AMAZON in Belgium ➡️AMAZON in Poland ➡️AMAZON in Sweden ⭐️The best sales & deals online!@BestenDeals #Amazon#kws

Hashtags

Top Telegram Channels - Europe

@topchannels_europe · Post #686 · 31.01.2026 г., 09:12

⭐️Promotional offer from AMAZON: ➡️Ring Indoor Camera (2nd Gen.) | Surveillance camera for indoor use | 1080p HD video, privacy screen protection, Wi-Fi, ideal for pets ➡️https://amzn.to/47glRLi 💶 49.99€-> 34.99€ (-30%) 🎉1,000+ purchased ⚠️The quantity and duration of the offer are limited!#Amazon#kws ⭐️The best offers & deals online!➡️@BestenDeals

Hashtags

Top Telegram Channels - Europe

@topchannels_europe · Post #673 · 22.01.2026 г., 09:39

⭐️Promotional offer from AMAZON: ➡️UGREEN Nexode Power Bank 20000mAh, 165W Fast Charging, 65cm Retractable Cable, Compatible ➡️https://amzn.to/4qAG3A1 💶 89.99€-> 59.99€ (-33%) 🎉ends in 14 hours ⚠️The offer quantity and duration are limited!#Amazon#kws ⭐️The best offers & deals online!➡️@BestenDeals

Hashtags

Top Telegram Channels - Europe

@topchannels_europe · Post #659 · 15.01.2026 г., 09:37

⭐️Promotional offer from AMAZON: ➡️KONO 55cm Hand Luggage Case Trolley Set 2 Pieces Luggage Sets, Small Case with Wheels Hand Luggage Set with Ryanair Travel Bag 40x20x25cm ➡️https://amzn.to/4pQQK0g 💶 59.99€-> 50.98€ (-15%) 🎉 ⚠️The quantity and duration of the offer are limited!#Amazon#kws ⭐️The best offers & deals online!➡️@BestenDeals

Hashtags

Top Telegram Channels - Europe

@topchannels_europe · Post #652 · 13.01.2026 г., 12:08

⭐️Aktionsangebot von AMAZON: ➡️Collagen Pulver 1 kg – Kollagenhydrolysat Peptide Typ I, II & III – Geschmacksneutrales Eiweißpulver – Made in Germany – Wehle Sports (1000g (1er Pack) ➡️https://amzn.to/4bv5yxL 💶 39,99€-> 30,59€ (-24%) 🎉10.000+ sell ⚠️Angebotsmenge und -dauer sind begrenzt!#Amazon#kws ⭐️Die besten Angebote & Deals online!➡️@BestenDeals

Hashtags

Top Telegram Channels - Europe

@topchannels_europe · Post #648 · 10.01.2026 г., 09:54

⭐️Promotional offer from AMAZON: ➡️Glückstoff® Orthopaedic Pillow (Certified for all Sleep Types) Pillow for Neck Pain made from Memory Foam | Neck Support Pillow Ergonomic Head Pillow Side Sleeper Pillow Grey ➡️https://amzn.to/3LEsBM7 💶 89.90€-> 67.91€ (-24%) 8.000+ purchased🎉 ⚠️The quantity and duration of the offer are limited!#Amazon#kws ⭐️The best offers & deals online!➡️@BestenDeals

Hashtags

Top Telegram Channels - Europe

@topchannels_europe · Post #768 · 14.04.2026 г., 07:55

⭐️Special offer from AMAZON: ➡️1. JACK & JONES Men's Blouson Jacket 💶 49.99€ -> 20.30€ (-59%) ✨ ➡️2. Men's Straight Leg Joggers, Long Pants with Open Hem, Loose Fit Sports Pants, Comfortable Training Pants 💶 59.98€ -> 29.31€ (-51%) ✨ ⭐️The best offers & deals in Europeonline: ➡️@BestenDeals #Amazon#kws#look

12
ПретходнаСтраница 1 од 2Следна