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

Резултати

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

Пребарај: #championsleague

当前筛选 #championsleague清除筛选
Futplanet

@Fut_planet · Post #15829 · 11.09.2025 г., 16:03

🚨El Metropolitano será la sede de la final 2027 🚨 La Uefa ha hecho oficial la vuelta de la final de la Champions League al Metropolitano. Ya en el 2019 el estadio Colchonero acogió la final Liverpool Vs Tottenham. @Fut_Planet⚜#Championsleague🏆

TONlines – News

@tonlines · Post #6958 · 29.04.2025 г., 10:07

Fanton: Win an Official NFT Card from Today's Champions League Matches #Fanton#NFT#ChampionsLeague Fanton is offering the chance to win an official NFT card of Zenit’s Maxim Glushenkov from today's matches, including Arsenal vs. PSG. Participate in various tournaments and support your favorite teams for a chance to win. Source: link @tonlines

TONlines – News

@tonlines · Post #7616 · 25.11.2025 г., 17:11

⚡️Fanton EN: Tuesday Battles Heat Up Before Champions League #ChampionsLeague#Jackpot Fanton EN has unveiled Tuesday Battles featuring 12 exciting football duels, gearing up for the Champions League. With minimal participation costs and significant stakes, including a whopping $400 Jackpot, participants have the chance to engage in thrilling contests and potentially win big. Source: link @tonlines

EdgeMarket.AI 📣

@edgemarketai · Post #8092 · 05.04.2026 г., 08:50

Sporting vs Arsenal Champions League Quarter Final Turn this match into a live signal on EdgeMarket AI proposes the outcome The community validates the result Participate using $SIGNAL or $BETON Earn from accuracy Connect your BSC wallet to get started 100 $BET for connecting Points convert before ICO Join now https://edgemarket.ai/bnb/football/who-will-win-sporting-lisbon-vs-arsenal/statistics/69cfad7d5e16d74b01b8374e #EdgeMarket#Crypto#Web3#Football#ChampionsLeague

TONlines – News

@tonlines · Post #6854 · 19.04.2025 г., 10:48

⚡️Fanton EN: EPL Gameweek 31 Preview and Strategies #EPL#Liverpool#ChampionsLeague Fanton EN covers the upcoming EPL Gameweek 31, highlighting key strategies and matches to watch. Liverpool and Arsenal are favored, while Aston Villa vs Newcastle is a decisive clash for Champions League spots. Key player picks include Salah and selections from City's attack. EPL fans can participate in the Grand EPL $5,000 event. Source: link @tonlines

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