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

Резултати

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

Пребарај: #neurotech

当前筛选 #neurotech清除筛选
IELTS|Newspapers & Magazines|English

@emagzinewspars · Post #9562 · 17.11.2025 г., 03:17

#The_Time🇺🇸📕[PDF]⬇️ 10 #November2025 #Weekly_Magazines For learning, for free(dom). @backupofmagazines Brain-computer interfaces are moving from labs into real lives, restoring sight and motion while redefining what #NeuroTech means for humanity. TIME explores how chips implanted in the body reshape independence, ethics and care, a story resonating across #AI, #HealthTech and #Futurism. Politics shifts in New York as Eric Adams’ tenure is reassessed, while #SportsCulture returns to center stage with Lindsey Vonn preparing for the 2026 Olympics. Striking visuals from Austria add emotional weight to a week shaped by innovation, leadership and resilience. #TechNews#Innovation

Venture Village Wall 🦄

@venturevillagewall · Post #3938 · 21.01.2025 г., 13:00

Massive USDC Minting and Meme Coin Scam 🚨 50M USDC minted at USDC Treasury, totaling $50.05M. Meanwhile, investors are falling victim to a scam involving fake Trump-related meme coins. Beware of various tokens like BARRON and IVANKA that are misleadingly launched under false pretenses, all funnelling funds to a scam wallet. ⚠️ Over 600 such tokens already spotted! More details here. AI funding news: - Qventus: $85M for AI healthcare ops. - Prophecy.io: $47M for data pipeline solutions. - Gesynta Pharma: $27.27M for new drugs. - Leap Services: $20M for omnichannel retail platform. - NeuroBionics: $5M for advancing neurotech. - Atlantic Sea Farms: $3.80M for sustainable seaweed farming. Find more funding details in the summary! #USDC#Crypto#AI#Funding#MemeCoins#Scams#Healthcare#Data#Pharma#Retail#Neurotech#Seafood#Tech#Investments#Investing#Finance#Blockchain