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

Пребарај: #newcourse

当前筛选 #newcourse清除筛选
Andijan Development Center

@adceducate · Post #8453 · 09.04.2024 г., 12:58

🎤 Great news! 🌟 We are excited to announce the launch of our new public speaking course at ADC! 🏫 If you want to overcome the fear of public speaking, improve your presentation skills, or simply become a more effective communicator, our course is designed for you. With experienced instructors, a supportive environment, and a program focused on real-life success, we are here to help you find your voice and make an impact. 👩‍🏫👨‍🏫 Join us on a journey of development, confidence, and empowerment. Classes are starting soon, and spaces are limited, so book your spot today! ☎️For more details: 74 2261078 74 2281121 74 2281666 74 2276163 74 2252536 #PublicSpeaking#FindYourVoice#Empowerment#CommunicationSkills#Education#NewCourse#JoinUs

PRICE ACTION EXPERT

@priceactionexpert · Post #8031 · 25.01.2025 г., 11:43

https://x.com/priceactiongann/status/1870116486494466125 #nifty50#nifty#gold#xauusd New Course: "Price Calculus" - Master the Art of Market Analysis Comprehensive Learning Path: 1. Patterns: Dive into the most critical and frequently used patterns in trading. 2. Market Dynamics: Understand the branches of price calculus and their application under various market conditions. 3. Structural Analysis: Learn how patterns and structures dictate price movements. Top-Down Analysis: 1. Chart Mastery: Detailed analysis from higher to lower time frames. 2. Market Characteristics: Essential knowledge for long-term survival in trading. Gann Techniques: 1. Gann Square Utilization: Learn the intricacies of Gann Square and its application in charting. 2. Square Relationships: Explore the relation between multiple squares and their impact on price. 3. Square Numbers : Practical use of square numbers and the Square of 9. Integrated Approach: 1. Correlation of Concepts: How Gann's concepts integrate with price patterns to form a cohesive analysis method. 2. Mastery of Price Calculus: Combine all elements into a complete methodology for mastering price movements. Contact in Telegram and X alone: Available by the end of January or first week of 2025. Give your maximum support thanks 🙏❤️🙏 #banknifty#stockmarket#stocks#gann#trading#priceaction #newcourse#course#astrology#financialastrology#numerology

PRICE ACTION EXPERT

@priceactionexpert · Post #7958 · 20.12.2024 г., 14:38

https://x.com/priceactiongann/status/1870116486494466125 #nifty50#nifty#gold#xauusd New Course: "Price Calculus" - Master the Art of Market Analysis Comprehensive Learning Path: 1. Patterns: Dive into the most critical and frequently used patterns in trading. 2. Market Dynamics: Understand the branches of price calculus and their application under various market conditions. 3. Structural Analysis: Learn how patterns and structures dictate price movements. Top-Down Analysis: 1. Chart Mastery: Detailed analysis from higher to lower time frames. 2. Market Characteristics: Essential knowledge for long-term survival in trading. Gann Techniques: 1. Gann Square Utilization: Learn the intricacies of Gann Square and its application in charting. 2. Square Relationships: Explore the relation between multiple squares and their impact on price. 3. Square Numbers : Practical use of square numbers and the Square of 9. Integrated Approach: 1. Correlation of Concepts: How Gann's concepts integrate with price patterns to form a cohesive analysis method. 2. Mastery of Price Calculus: Combine all elements into a complete methodology for mastering price movements. Contact in Telegram and X alone: Available by the end of January or first week of 2025. Give your maximum support thanks 🙏❤️🙏 #banknifty#stockmarket#stocks#gann#trading#priceaction #newcourse#course#astrology#financialastrology#numerology