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

Резултати

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

Пребарај: #learntocode

当前筛选 #learntocode清除筛选
Dasturlash hayoti️️ ️

@dasturlash_hayoti · Post #3990 · 05.10.2025 г., 06:58

#DasturlashHayoti#LearnToCode#Programmer Har bir dasturchi bilishi kerak bo‘lgan 5 ta bepul manba 🆓Pul to‘lamasdan bilim olishning eng zo‘r manbalari: 1️⃣FreeCodeCamp — front-end’dan tortib back-end’gacha 2️⃣roadmap.sh — qaysi yo‘nalishdan boshlashni aniq ko‘rsatadi 3️⃣Frontend Mentor — haqiqiy dizayn asosida kod yozish mashqi 4️⃣CSS Battle — o‘yin orqali CSS o‘rganasiz 5️⃣DevDocs — barcha texnologiyalar hujjatlari bitta joyda Bilim — eng yaxshi investitsiya. Ayniqsa, pulsiz bo‘lsa yanada yoqimli 😄 Shunaqa postlar davom etsin desangiz, ulashib qo‘ying — birga o‘rganamiz! 💪 💻@dasturlash_hayoti— Dasturchilar uchun eng kerakli maslahatlar va foydali kontent

Repositorio data science

@repo_science · Post #4259 · 08.12.2025 г., 03:46

#SpringBoot#RESTAPI#BackendDevelopment#CodeWithMosh#Java#StripeIntegration#CloudDeployment#LearnToCode 🚀 Ready to take your backend skills to the next level? 🔗Spring Boot: Mastering REST API Development🎓 - Learn to build clean, secure RESTful APIs - Add authentication, role-based access, and JWT security 🔒 - Integrate Stripe for real payment processing 💳 - Deploy your app and database to the cloud ☁️ - Apply industry best practices for production-ready code 🛠 👉 Join now @repo_science and start building real-world projects like a pro!

#HaSab

@Hasab_2016 · Post #160 · 07.04.2025 г., 07:58

YES! 🙌 It's a wrap! 🥳 The HaraCoders Bootcamp training, brought to you by the awesome Rotaract Club of Kuriftu 🤝, BuildX Ethiopia , Sira Ale, and Addis Ababa University College of Veterinary Medicine and Agriculture , has been a HUGE success! We're sending out waves of gratitude to everyone involved and a BIG congrats to our fantastic trainees! 🎉 So proud of you all! 🔥 Stay tuned... round 2 might be closer than you think! 😉🚀 #AddisCoders#BuildXEthiopia#TechForAll#EmpowerTheFuture#CodingBootCamp#EthiopianTech#LearnToCode#CodingForChange #Rotary #Rackuriftu #100yearsofserviceinafrica #Rotaract #District9212 #RotaractEthiopia

#HaSab

@Hasab_2016 · Post #152 · 03.02.2025 г., 17:21

🚀 Exciting News! 🚀 The AddisCoders BootCamp is brought to you by BuildX Ethiopia in partnership with Rotaract Kuriftu, SERRALE, and Addis Ababa University! 🎓💻 Together, we’re empowering Ethiopian youth with hands-on web development skills to build the future of tech! 🔥 Stay tuned for more updates! #AddisCoders#BuildXEthiopia#TechForAll#EmpowerTheFuture#CodingBootCamp#EthiopianTech#LearnToCode#CodingForChange #Rotary #Rackuriftu #100yearsofserviceinafrica #Rotaract #District9212 #RotaractEthiopia

Repositorio data science

@repo_science · Post #3109 · 28.04.2023 г., 17:58

#datascientist#datascience#datasciencejobs#dataanalysis#data#dataanalyst#dataanalytics#dataanalystjobs#analytics#python#pythonprogramming#rprogramming#sql#excel#statistics#testing#softwaretesting#projects#projectmanagement#agile#computerscience#programming#webdevelopment#softwaredevelopment#roadmap#visualization#learningeveryday#learning#tutorials#learntocode#apache#powerbi#tableau#machinelearning#ml#ai#artficialintelligence#deeplearning#bigdata#bigdataanalytics#algorithms#mathematics#datastructures#kaggle#nlp#reinforcementlearning#sql#nosql#databases#mongodb ----- Canal principal:@repo_science Cupones: @freecoupons_reposcience -----