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

Пребарај: #videochat

当前筛选 #videochat清除筛选
BotsGram®

@botsgram_cu · Post #4863 · 07.08.2022 г., 15:05

@thekillpro_musicbot Con este bot puede descargar canciones y videos, además de poder reproducir música en un videochat o chat de voz 🎧🎤 #musica#videochat#chatvoz (Visto en @Botsgram_cu)

🦅 [ perspective ix ]

@perspectiveix · Post #1951 · 30.03.2020 г., 13:30

​​🤳Video Chat Apps Rise to Prominence Amid Pandemic As a significant part of the world population is currently on lockdown in an attempt to contain the #coronavirus pandemic, people are turning to technology to work, communicate and stay in touch with their loved ones. Unsurprisingly, workplace communication tools such as #Slack and #MicrosoftTeams have seen a jump in usage as working from home has become the new norm in recent weeks. People are also making use of similar tools in their personal lives, however, leading to a spike in downloads of #VideoChat apps. According to Priori Data, global downloads of #Skype, #Houseparty and #Zoom each surged by more than 100% in March, with the latter proving particularly popular among people meeting up virtually while being confined to their homes. The videoconferencing app was downloaded nearly 27 million times this month, up from just 2.1 million times in January. While Zoom is definitely the rising star among video chat apps, Skype remains far ahead in terms of active users. According to Priori Data, the #Microsoft-owned service had 59 million daily active users on its iOS and Android apps in March, compared to just 4.3 million for Zoom. It needs to be noted though, that many people also use Skype for other ways of communication, while Zoom has specialized on video conferences, so it may not be a fair comparison to make. 🦅@PerspectiveIX via Statista.