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

Пребарај: #problemsolving

当前筛选 #problemsolving清除筛选
Digital.edu IT Career

@digitalitvacancy · Post #160 · 27.01.2025 г., 07:26

Dasturlashga qo'l urgan, lekin nimadan boshlashni bilmaydiganlar uchun 3-5 yillik plan: — Nerd rejimiga o'ting: kuniga kamida 6 soat dasturlash bilan band bo'ling — Computer Science mavzularini chuqur o'rganing — Muntazam algoritmik masalalarni yeching (codewars, leetcode, va hokazo) — Bitta dasturlash tilini mukammal o'rganing — Web, mobil, yoki desktop development uchun kerak bo'lgan texnologiyalarni o'rganing — O’zingizni pet proyektlaringizni yarating — Har kuni ko'p kod yozing — Tez-tez interview qiling (ishingiz bo'lsa ham) — Vaqtida uxlang, ovqatlaning, va sport bilan shug'ullaning Qolgani (ish, daromad, va xurmat) o'zi keladi. Natija darxol ko'rinmaydi, lekin albatta keladi - haqiqiy yutuqlar vaqt talab qiladi. Jarayondan zavq oling! #Coding#ComputerScience#CS#ProblemSolving#Dasturlash#Programming#SoftwareEngineering#IT

MEZON Inspiring School

@mezon_school · Post #3325 · 13.01.2026 г., 06:02

🇷🇺 RUS / 🇬🇧 ENG / 🇺🇿 UZB 🧠📐 Математика — это не про заучивание, а про мышление! Продолжаем разбирать задачи олимпиады Mezon прошлого года. Сегодня — пара интересных задач для 4 класса: учимся рассуждать, искать нестандартные ходы и получать удовольствие от процесса 💡 #MezonSchool#МатематическаяОлимпиада #Математика#УчимсяДумать#Логика 🇬🇧 English 🧠📐 Math is about thinking, not memorizing! We continue analyzing problems from last year’s Mezon Math Olympiad. Today we’re working through a couple of problems for Grade 4, focusing on reasoning, creativity, and smart strategies 💡 #MezonMath#MathOlympiad#ElementaryMath #ThinkingSkills#ProblemSolving 🇺🇿 O‘zbekcha 🧠📐 Matematika — yodlash emas, fikrlash haqida! O‘tgan yilgi Mezon matematika olimpiadasi masalalarini tahlil qilishni davom ettiramiz. Bugun — 4-sinf uchun bir nechta qiziqarli masala, mantiqiy fikrlash, noodatiy yechimlar va jarayondan zavqlanishga e’tibor qaratamiz 💡 #MatematikaOlimpiadasi #MantiqiyFikrlash#MasalaYechish

Venture Village Wall 🦄

@venturevillagewall · Post #3588 · 20.12.2024 г., 10:29

AI Marketer Launches for $29 Introducing Nikolai's service, MarketOwl, which provides virtual marketing teams for small businesses. The AI-driven platform automates content creation and identifies potential customers. Currently, it supports around 100 users monthly, generating about $3k in revenue. The concept originated from Nikolai's observations of small companies lacking marketing resources, expertise, and time. After initial failures with a marketing strategy MVP, he pivoted to develop the AI marketer. Engagements in a dedicated subreddit led to high conversion rates for subscriptions. Successful products arise from addressing real audience problems. To effectively enter the market, consider using the Plan-Kapkan consisting of 35 steps for launching. #MarketOwl#AI#Marketing#ContentCreation#SmallBusiness#SaaS#VirtualTeam#Startup#Entrepreneurship#MVP#ProblemSolving#Automation#CustomerAcquisition#AudienceEngagement#Subscription#Revenue#Strategy#PlanKapkan#BusinessGrowth#MarketingTools