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

Пребарај: #accommodation

当前筛选 #accommodation清除筛选

🏨Recommended hotels for the RAREMET-2026 participants Dear participants of the RAREMET-2026 Congress! The Congress website contains information about hotels that are ready to receive you on special terms during the event. In this section you will find addresses, promo codes for reservations and their validity periods. 📌 Details are available on our website. 🗓Dates of the Congress: RAREMET-2026 will be held on May 20-22 in Moscow at the RTU MIREA. The organizer is Giredmet JSC. 📱 Subscribe to our channels: Telegram: t.me/raremet2026 MAX: max.ru/id7707072637_gos22 See you at the main forum of the rare metal industry! #RAREMET2026#RAREMET2026#hotels#accommodation#participants

🏨 ACCOMMODATION SECRETS: ETHIOPIA'S HIDDEN GEMS | ድንቅ የሆኑ የኢትዮጵያ ማረፊያ ቦታዎች 🌟 From royal palaces to mountain hideaways - discover where legends stay in the Horn of Africa. 🏨 LUXURY HOTELS | ቅንጡ ሆቴሎች • Sheraton Addis: $200-300/night, presidential suite where Obama stayed • Hyatt Regency: $150-250/night, rooftop views of Entoto Mountains • Radisson Blu: $120-200/night, modern amenities in heart of city • Four Points Sheraton: $100-180/night, business traveler favorite 🏡 TRADITIONAL GUESTHOUSES | ባህላዊ እንግዳ ማረፊያዎች • Yod Abyssinia: $60-80/night, authentic Ethiopian architecture • Taitu Hotel: $40-70/night, historic charm in Piazza district • Local family homestays: $15-30/night, genuine cultural immersion • Traditional tukuls: $25-50/night, round stone houses with thatched roofs 🏔️ ECO-LODGES & WILDERNESS | ተፈጥሮ ተስማሚ ስፍራዎች • Simien Lodge: $180-250/night, gelada monkeys at your doorstep • Buska Lodge (Omo Valley): $120-200/night, tribal cultural experience • Danakil camping: $40-80/night, sleep under Milky Way in Mars landscape • Lalibela mountain lodges: $80-150/night, rock churches views 💰 BUDGET ACCOMMODATIONS | የእርስዎን በጀት ያማከሉ ማረፊያዎች • Backpacker hostels: $8-15/night, shared dorms with Wi-Fi • Pension houses: $12-25/night, family-run, breakfast included • Government rest houses: $5-12/night, basic but clean • Church compounds: $3-8/night, unique spiritual experience 📱 BOOKING PLATFORMS & TIPS • Best platforms: Booking.com, Agoda, local Ethiopian sites • Direct booking: Often 10-20% cheaper, call hotels directly • Peak seasons: Christmas (Jan 7), Timkat (Jan 19), Meskel (Sept) • Negotiation: Always possible except peak times 💡 INSIDER SECRETS: Book mountain lodges 2+ months ahead. Many hotels accept USD directly. Traditional coffee ceremony often included. Ask for "faranji price" vs local rate. 🏆 From $3 sacred sanctuaries to $300 presidential suites - Ethiopia accommodates every dream! #EthiopiaHotels#ኢትዮጵያ#Accommodation#TravelSecrets#HiddenGems