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

Резултати

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

Пребарај: #languages

当前筛选 #languages清除筛选
help florin закрыт

@HELPFLORIN · Post #6796 · 20.03.2023 г., 07:34

𖥻 🍵 ›› ֗ . . ✦ › › ᥴуⲙᥱρκᥙ ; цᥱρκ᧐ʙь δ᧘ᥲᴦ᧐ᥴ᧘᧐ʙᥱнᥙᥱ нᥱδ᧐ жᥙᴛᥱ᧘ᥱᥔ κ᧐ᥴⲙ᧐ᥴ ;ᤋʙᥱᤋд᧐ᥰᥲд ➫ 𝘁𝗮𝗴𝘀 — #languages `` взяⲗυ ♡゙ — ‹ + › ⲃ ⲕⲟⲙⲙ.

Hashtags

Daily Channels

@dailychannels · Post #6730 · 06.03.2026 г., 01:00

Channel: Learn English in Ethiopia Members: ~12.12K 💢 Username: @englishlearn_ethiopia Description: Home of English learners! Buy ads: https://telega.io/c/EnglishLearn_Ethiopia 🏷 Tags: #languages https://lve.to/jg2rmu2jlz

Hashtags

Daily Channels

@dailychannels · Post #6682 · 14.02.2026 г., 13:00

Channel: Urban Dictionary Members: ~2.01K 💢 Username: @urbandictionary Description: Read new words from Urban Dictionary every day. Source: urbandictionary.com Bot: @UrbanDictionaryBot Chat: @UrbanDictionaryChat (Unofficial) 🏷 Tags: #languages https://lve.to/uahjrdrvyo

Hashtags

Daily Channels

@dailychannels · Post #6388 · 02.10.2025 г., 13:00

Channel: BBC Learning English Members: ~73.81K 💢 Username: @english_bbc_learning Description: ️ http://linkin.bio/bbclearningenglish 🏷 Tags: #languages https://telegramchannels.me/channels/english_bbc_learning

Hashtags

Daily Channels

@dailychannels · Post #6175 · 02.07.2025 г., 01:00

Channel: English with shei Members: ~4.72K 💢 Username: @englishwithshei Description: More English!🦸 ‍ ️ 🏷 Tags: #languages https://telegramchannels.me/channels/englishwithshei

Hashtags

Daily Channels

@dailychannels · Post #5886 · 12.03.2025 г., 01:00

Channel: Language Trivia Members: ~6.36K 💢 Username: @languagetrivia Description: Are you a language enthusiast looking for a fun challenge? @languagetrivia delivers daily quizzes and trivia, from simple multiple-choice questions to riddles and 'guess the language' challenges. For inquiries, contact @venklypaul 🏷 Tags: #languages https://telegramchannels.me/channels/languagetrivia

Hashtags

Daily Channels

@dailychannels · Post #5875 · 09.03.2025 г., 13:00

Channel: Babelgram News Members: ~64.68K 💢 Username: @babelgram Description: All about @BabelgramBot. The best bot in Telegram for translations Discussion group: https://t.me/+ZuHYMBvgjsU1YTQ0 🏷 Tags: #languages https://telegramchannels.me/channels/babelgram

Hashtags

Daily Channels

@dailychannels · Post #6507 · 25.11.2025 г., 13:00

Group: Search English Groups & Channels Members: ~2.3K 💢 Username: @seekcommunity Description: This group helps you discover English groups and channels. Simply send a word here, and you’ll receive matching results. Seek Bot: @seek Seek Announcement: @SeekAnnouncement 🏷 Tags: #languages #seek,telegram,deepseek https://telegramchannels.me/groups/seekcommunity

Bots Channel

@BotsChannel · Post #215 · 17.05.2016 г., 14:02

🏆Bot of the day🏆 @fixmebot This Bot helps you to write in English and efficiently corrects texts. With @fixmebot you won’t need to waste time trying to find the correct way to write a sentence. Checking grammar has never been so easy! #Grammar#English#Languages

🌍📚 The office of the Honorary Consul of South Africa in Yekaterinburg hosted a workshop on consecutive interpretation for 11th-grade students of School No. 212. 🇿🇦 During the session, we explored the culture and history of South Africa, while also delving into the professional life of interpreters. 🗣 The workshop was conducted in both Russian and English: students took turns stepping into the shoes of an interpreter, followed by a group analysis of their performance. ✨ The students got a firsthand experience of what it’s like to work as an interpreter, gaining valuable insight into this dynamic profession! #SouthAfrica#Yekaterinburg#Translation#Education#School#Culture#Languages#InternationalTranslationDay

12
ПретходнаСтраница 1 од 2Следна