@TestFlightX · Post #34125 · 23.09.2024 г., 18:24
#FLIP#FLASHCARDS https://testflight.apple.com/join/J2B2WMZY
Hashtags
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
Пребарај: #flashcards
@TestFlightX · Post #34125 · 23.09.2024 г., 18:24
#FLIP#FLASHCARDS https://testflight.apple.com/join/J2B2WMZY
Hashtags
@testflightynoti · Post #37537 · 03.05.2026 г., 21:56
#Cruxly#AI#Quiz#amp#Flashcards Join the Cruxly AI - Quiz & Flashcards beta on ✈️#TestFlight 🔗 Link: https://testflight.apple.com/join/muAr9ASt Shared by Dimitri
@githubtrending · Post #14651 · 01.05.2025 г., 11:30
#python#agplv3#education#flashcards#foreign_language#hacktoberfest#hacktoberfest2022#language_learning#python#second_language_acquisition#spaced_repetition#svelte LibreLingo is a free, community-driven language-learning platform offering courses like Spanish, German, and French through interactive exercises, spaced repetition, and progress tracking across devices, while allowing users to contribute and modify content for a collaborative learning experience[1][4][5]. https://github.com/kantord/LibreLingo
@githubtrending · Post #15549 · 08.03.2026 г., 12:00
#python#ai_automation#api#audio_overview#claude#cli_tool#flashcards#google_notebooklm#notebooklm#notebooklm_api#notebookln#podcast_generator#python#python_api#quiz_generator#sdk#skills#study_tools notebooklm-py is a free Python tool and CLI for full access to Google NotebookLM's features, like creating notebooks, adding sources (URLs, PDFs, YouTube), chatting, deep research, and generating podcasts, videos, quizzes, slides, mind maps in formats like MP3, MP4, JSON. It offers extras the web lacks, such as batch downloads, editable PPTX, and mind map data. You benefit by automating research, content creation, and exports programmatically for faster prototypes, pipelines, or AI agents—saving time on manual UI work. https://github.com/teng-lin/notebooklm-py