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 слични објави

Пребарај: #luxurywatches

当前筛选 #luxurywatches清除筛选
Online Education

@OnlineEducation10 · Post #646 · 07.09.2021 г., 06:08

Don't miss the 3D engraving of India's first satellite, the Aryabhata, at the back of the Apogee watches. #WatchReview by Murali K Menon at https://www.moneycontrol.com/news/luxury-lifestyle/bangalore-watch-companys-apogee-a-watch-inspired-by-isro-7368871.html #Apogee#IndianSpaceResearchOrganisation#Isrowatch#luxurywatches#ISRO @onlineeducation10

美女/时尚图片分享

@tgbestpicture · Post #9804 · 08.02.2026 г., 12:00

631 个赞,6 条评论 - watch.magazzine 于 2022 年 12 月 20 日:“壮观的皇家橡树万年历 #26579CE... 631 条赞,6 条评论 - watch.magazzine 于 2022 年 12 月 20 日发布:“黑色陶瓷款皇家橡树万年历 #26579CE 腕表。您对它的评分为 1-10 分吗?内容来自@wristaficionado #audemarspiguet#audemarspiguetwatch#audemarspiguetwatches#audemars#luxurywatches#audemarsholic#watchesfor… pinterest​.com • Feb 8, 2026

Venture Village Wall 🦄

@venturevillagewall · Post #3603 · 20.12.2024 г., 17:21

Kettle Secures $4M Funding Luxury watch trading marketplace Kettle has raised $4M in a funding round led by ParaFi Capital. Significant contributions came from Zee Prime Capital, Kronos Research, Signum Capital, IOSG Ventures, Puzzle Ventures, OSF, and Gmoney. #LuxuryWatches#Funding#Investment#Marketplace#ParaFiCapital#ZeePrimeCapital#KronosResearch#SignumCapital#IOSGVentures#PuzzleVentures#OSF#Gmoney

Venture Village Wall 🦄

@venturevillagewall · Post #4027 · 30.01.2025 г., 07:00

Trump Launches Crypto-Themed Watches Donald Trump has launched a line of luxury watches, including crypto-themed models featuring the Bitcoin logo. One limited edition model, adorned with gold, diamonds, and sapphires, is priced at $100,000, with only ten available. Read more about this and other updates on ForkLog. #Trump#Crypto#Watches#Bitcoin#Luxury#Fashion#LuxuryWatches#News#Updates#Launch#VIP#Investing#LimitedEdition#LuxuryLifestyle#NFT#Wealth#Collectibles#Investment#Trends#AI