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

Резултати

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

Пребарај: #tickets

当前筛选 #tickets清除筛选
TONlines – News

@tonlines · Post #7704 · 04.12.2025 г., 12:47

Gatto: Prepare for the Festive Crocottery! #Gatto#tickets Players with SBT from Gatto are eligible for free tickets in tomorrow's Crocottery. Ensure wallets with SBT are connected to Gatto by December 5th to receive tickets. Source: link @tonlines

Trump's Ear

@trumpsear_tg · Post #1942 · 23.12.2025 г., 16:05

American Airlines fliers are fuming after the carrier cut its program awarding bonus miles and other travel perks to passengers who purchase a basic economy ticket. According to the airline’s website, the policy change is in effect for travelers who booked basic economy tickets on or after Dec. 17 at 12 a.m. CT. #Airlines#tickets 👂More on Trump's Ear

GitHub Trends

@githubtrending · Post #14709 · 15.05.2025 г., 13:00

#python#bilibili#bilibili_api#manga#tickets biliTickerBuy is a free, open-source tool that helps you easily buy items on Bilibili’s member shop. You can quickly download and install it from the official releases page, and there’s a clear user guide available. If you have questions or find bugs, you can ask for help or report issues directly on the project’s page. The tool is supported by a community of contributors, and you can see how popular it is by checking its star history. Using biliTickerBuy makes shopping on Bilibili simpler and more convenient, and you can support the project with donations if you like it. https://github.com/mikumifa/biliTickerBuy

FlyArystan

@FlyArystan_official · Post #37 · 16.07.2019 г., 12:32

Арзан билеттерді ұстап үлгеріңіз!😍 Тамызда: Алматы-Тараз-Алматы 3999 тг бастап Қыркүйекте: Алматы-Нұр-Сұлтан-Алматы 6999 тг бастап Алматы-Қарағанды-Алматы 5999 тг бастап Алматы-Павлодар-Алматы 6999 тг бастап Алматы-Шымкент-Алматы 4999 тг бастап Қазанда: Алматы-Орал-Алматы 12999 тг бастап *арзан бағалы билеттер рейстің толуына байланысты өзгеруі мүмкін 🛫🛫🛫 Поймайте билеты по вкусным ценам!😍 Август: Алматы-Тараз-Алматы от 3999 тг Сентябрь: Алматы-Нұр-Сұлтан-Алматы от 6999 тг Алматы-Қарағанды-Алматы от 5999 тг Алматы-Павлодар-Алматы от 6999 тг Алматы-Шымкент-Алматы от 4999 тг Октябрь: Алматы-Орал-Алматы от 12999 тг *наличие дешевых билетов зависит от загруженности рейса 🛫🛫🛫 Catch our lowest fares!😍 August: Almaty-Taraz-Almaty from 3999 KZT September: Almaty-Nur-Sultan-Almaty from 6999 KZT Almaty-Karagandy-Almaty from 5999 KZT Almaty-Pavlodar-Almaty from 6999 KZT Almaty-Shymkent-Almaty from 4999 KZT October: Almaty-Uralsk-Almaty from 12 999KZT *the availability of the lowest fares directly depends on the passenger load factor of a flight 🛫🛫🛫 #flyarystan#lowfares#lowcosters#tickets#билеттер#билеты#перелеты