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

Резултати

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

Пребарај: #publicsafety

当前筛选 #publicsafety清除筛选
America 🇺🇸 News & Politics

@America · Post #10377 · 12.03.2026 г., 05:56

🔫🇺🇸GUN VIOLENCE EXPLODES: 65 MASS SHOOTINGS IN JUST 9 DAYS 🔹 Austin deadly shooting: 3 killed, 15 injured on West Sixth Street March 1st 💀 🔹 2,333 homicides already recorded in first quarter of 2026 alone 📊 🔹 130 children (ages 0-11) killed in gun violence this year so far 👶💔 🔹 600 teenagers (12-17) lost their lives to firearms nationwide 🎓😢 🔹 Oakland bar shooting: 2 dead, 5 bystanders wounded in random crossfire 🍸 Cincinnati music venue, Virginia Beach confrontations add to growing toll... 🎵⚰️ California leads with 26 mass shootings since records began — crisis deepens! 📈🏴‍☠️ #GunViolence#MassShooting#PublicSafety#Austin @america

Venture Village Wall 🦄

@venturevillagewall · Post #4311 · 05.03.2025 г., 10:00

Massive Funding Rounds Highlight Emerging Tech 🔍 Recent funding rounds spotlight key players in various industries: - Zenith Energy: $1.18B for remote off-grid and urban microgrid power solutions. More Info - Kommunalkredit Austria: $209.71M investment to enhance societal quality of life. More Info - Hanyang Technology: Secured $200M, focusing on technology development. More Info - Duetti: $200M to revolutionize music catalog acquisitions from independent artists. More Info - Peregrine Technologies: $190M aimed at improving public safety management. More Info - TK Elevator: $166.05M raised to enhance elevator technology. More Info - Zhipu AI: $137.27M funding for AI development, including high-precision knowledge maps. More Info - Geneus: $100M dedicated to science and technology advancements. More Info - Swap: $40M for enhancing ecommerce shipping and tracking. More Info - Atmosic: $40M for innovative battery-less technology solutions. More Info - Ocean Yield: $35M for investments in maritime assets. More Info - Viam: $30M towards AI and automation engineering solutions. More Info - Coalition: $30M for cybersecurity insurance and services. More Info - Danking Pharmaceuticals: $20.59M focused on innovative pharmaceutical research. More Info - IdentifySensors: $20M for biomarker detection technology. More Info - LlamaIndex: $19M for developing AI knowledge assistants. More Info - Heidi Health: $16.60M for AI-driven healthcare documentation. More Info - Prime Intellect: $15M for accessible AI development platforms. More Info #AI#VC#Energy#Tech#Pharmaceuticals#Ecommerce#Cybersecurity#Music#PublicSafety#Automation#HealthTech