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

Резултати

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

Пребарај: #learnenglish

当前筛选 #learnenglish清除筛选
BBC Learning English

@english_bbc_learning · Post #3698 · 28.09.2025 г., 09:41

🙄 Do you ever want to tell someone that you just don’t care? 🤷‍♂️🤷‍♀️ This expression is for you! 🐵⚠️Use it carefully though – it’s VERY informal! Write your answer in the comments and don’t forget to give this post a like! Do you have a similar expression in your language?⁣ ⁣ #learnenglish

ENGLISH TIPS & QUIZZES™️

@englishtipsquizzes · Post #131 · 18.02.2023 г., 10:23

🔰🔰🔰 Questions without inversion In informal conversation a question can sometimes have the same word order as in a statement. The question has a rising intonation • The machine gives change? ~ No, it doesn't. • You're travelling tomorrow?~ Yes. • The car is blue?~ That's right. • The car is what colour? ~ Blue. • They went which way?~ That way. We use this kind of question only when it follows on from what was said before. I need a return ticket to Paddington • You're travelling when?~ Tomorrow. #learnenglish#vocabulary 👉@wallstreetenglish_WSE

ENGLISH TIPS & QUIZZES™️

@englishtipsquizzes · Post #67 · 09.02.2023 г., 07:45

🔰When Someone Is Insistent/Pressuring You🔰 • I’d love to, but I really can’t/have to go/don’t have the time. • It’s been a pleasure, but I really have to go. • This simply isn’t the right time, unfortunately. • I would love to help you, but I’m already overcommitted as it is. • I wish I could be of more help to you, but I can’t. • I must respectfully decline. • I’m sorry, but I can’t help you. • I don’t have time for this at the moment. • Please leave me alone/stop pushing. • This conversation is unnecessary. • Maybe this is the way you get things done, but I don’t like it. • It’s useless; you’re wasting your efforts on me. • You’ll be wasting your time if you keep talking to me/pushing me. • Why don’t you take this up with someone who actually has the time? • You really should put your energy elsewhere. • If I need your help, I’ll ask for it. • The answer is no. • No is a complete sentence. • You’re pushing too hard—stop it! • Go bother somebody else! #learnenglish#vocabulary @wallstreetenglish_WSE @wallstreetenglish_WSE @wallstreetenglish_WSE

ENGLISH TIPS & QUIZZES™️

@englishtipsquizzes · Post #58 · 07.02.2023 г., 13:22

**🔰Air Lane VS Airline🔰** • Air lane (Also: airway ) a regular route of travel for aircraft: - This will enable controllers to squeeze an extra 20 percent traffic into the crowded air lanes. • Airline 1. Company that carries passengers and cargo by airplane: - The airline has announced it will run daily service to Florida. 2. A tube through which air is passed under pressure: - Any big truck lives and dies, steers and brakes, on its air-lines. #learnenglish#vocabulary @wallstreetenglish_WSE @wallstreetenglish_WSE @wallstreetenglish_WSE

ENGLISH TIPS & QUIZZES™️

@englishtipsquizzes · Post #51 · 06.02.2023 г., 09:15

🔰Adapted For Something VS Adapted To Something🔰 Adapted For Something —(of things) made suitable for a new use, situation, etc.: • The book was adapted for television as a four-part series screened by the BBC. Adapted To Something —(of people) accustomed or suitable to smth.: • I am not adapted to this business. • I was bred a farmer, and ought not to have left that occupation. #learnenglish#vocabulary

English Language

@Englishdaybyday · Post #6254 · 22.07.2025 г., 20:21

✈️ Conversations on the plane 🤣#english#learnenglish ▬▬▬▬▬▬▬▬▬▬▬▬ ➠@PhrasalCards ➠@SlangWords ➠@IdiomsLand ➠@Vocabulix ➠@GrammarCards ➠@EnglishGate ➠@StoryPage

Espresso English

@EspressoEnglish · Post #3922 · 17.08.2025 г., 19:16

😂At the dentist with Mike🩷 Comment Preply and I'll send you the link! ✨#english#learnenglish ▬▬▬▬▬▬▬▬▬▬▬▬ ➠@PhrasalCards ➠@SlangWords ➠@IdiomsLand ➠@Vocabulix ➠@GrammarCards ➠@EnglishGate ➠@StoryPage

Espresso English

@EspressoEnglish · Post #3867 · 07.07.2025 г., 19:56

😂At the dentist with Mike🩷 Comment Preply and I'll send you the link! ✨#english#learnenglish ▬▬▬▬▬▬▬▬▬▬▬▬ ➠@PhrasalCards ➠@SlangWords ➠@IdiomsLand ➠@Vocabulix ➠@GrammarCards ➠@EnglishGate ➠@StoryPage

123•••78
ПретходнаСтраница 1 од 8Следна