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

Резултати

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

Пребарај: #lilium

当前筛选 #lilium清除筛选
[NSFW] 每日百合本推送

@YuriYuriManga · Post #1579 · 17.09.2024 г., 11:11

女性: #舔阴#纯女性⚢ #狐女#兽耳#接吻💏#尾巴#贝合#虚拟主播#百合 原作: #Hololive 角色: #白上吹雪 语言: #汉语#翻译 团队: #LILIUM 原始地址:https://exhentai.org/g/3048271/a0b0e220ef 预览:[りーりうむ (アイガ)] 同居人との暑い休日 (白上フブキ、黒上フブキ) [中国翻訳] [DL版]

Venture Village Wall 🦄

@venturevillagewall · Post #3680 · 24.12.2024 г., 08:10

Investments Surge in Innovative Platforms A startup has raised nearly $50 million after seven years of self-funding, initiating a trend of significant investment in platforms that facilitate companies selling third-party services. Notably, similar platforms across various sectors have also attracted large funding this year, signaling a ripe market for investment in this area. In addition, recent reports highlight key developments in the tech sector, such as a sharp decline in YouTube traffic in Russia, the purchase of advertising services by ‘Avito’ and T2, and the closure of electric aircraft startup Lilium after failing to secure funding. Moreover, European AI startups have attracted $13.7 billion in venture capital this year, comprising 25% of the continent's VC funding. Read more about these developments here: https://fastfounder.ru/takaja-shema-raboty-rezko-stala-vostrebovannoj/ #Startup#Investment#Funding#Platforms#AI#Tech#YouTube#AdTech#Lilium#VentureCapital#Ethereum#Tether#Rumble#Advertising#MarketTrends#Growth#FinTech#Crypto#Inflow#Development#EuropeanMarket

Venture Village Wall 🦄

@venturevillagewall · Post #3711 · 25.12.2024 г., 10:00

Edtech Investments Hit 2014 Low 📉 Global investment in Edtech startups plummets to $3 billion this year, the lowest since 2014. Startups are distancing themselves from the Edtech label, impacting investor interest. 🧑‍🦼 'Моторика' acquires 51% of a wheelchair manufacturer, positioning itself in assistive technology ahead of an IPO planned for 2026. 🤖 OpenAI considers creating a humanoid robot, but new AI models remain the priority. ✈️ Lilium, the electric aircraft developer, may be saved by a consortium after announcing closures and layoffs. Read more: Financial Times, Vedomosti, The Information, TechCrunch #Edtech#Investment#Startups#AI#Robot#AssistiveTechnology#Lilium#MOTORIKA#FinancialTimes#Vedomosti#TheInformation#TechCrunch#Singapore#Cryptocurrency#UserExperience#MarketTrends#Technology#Innovation#Business#Funding