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

Пребарај: #writer

当前筛选 #writer清除筛选

🗓🇿🇦November 20 marks the birthday of Nadine Gordimer (1923–2014), one of South Africa’s most influential English-language writers. 🏅 Recipient of the 1991 Nobel Prize in Literature. ✊ A committed member of the African National Congress and an active voice in the struggle against apartheid. ⚖️ In 1964, Gordimer helped prepare Nelson Mandela’s defense speech for the Rivonia Trial. 📖 While in prison, Mandela wrote: “I read all of Nadine Gordimer’s novels that were not banned.” ✍️ In 1987, she played a key role in establishing the Congress of South African Writers (COSAW), an important cultural platform during the final years of apartheid. 🌍 Her work remains a powerful testament to the pursuit of freedom, justice, and human dignity. 📸 Photo: Wikipedia #SouthAfrica#Literature#NobelPrize#Writer#HumanRights#History

iGaming Freelance Content Writers/Translators (Native Speakers) #remote#удаленно#iGaming#content#writer#tango We’re looking for iGaming Freelance Content Writers/Translators (Native Speakers). Our digital holding is expanding and we’re looking for native Filipino speaking translators & writers for iGaming projects. You’re a perfect fit if you have: • 1+ year of proven experience in iGaming translation or content writing • Solid understanding of iGaming terminology and cultural specifics of your region • Native fluency in #Filipino + strong English (for reading source materials) • Ability to start immediately and meet deadlines reliably What you’ll do: • Translate and localize website content (JSON format) from English • Adapt texts considering cultural/linguistic nuances • Proofread and edit content as needed We offer: • Fully remote freelance / part-time work • Competitive rates (based on skills and experience) • Interesting tasks and professional team support • No test task – we trust your portfolio Let’s connect! ⏺Apply: @IvanRecruiter ➖➖➖➖➖➖➖➖➖➖➖ 🪩 Откликнуться быстрее других ➖➖➖➖➖➖➖➖➖➖➖

Desi Memes Funny Jokes

@DESI_MEMES_Funny_Jokes · Post #5485 · 19.10.2024 г., 11:09

. . . . . #attitude#explore#tranding#reelsinstagram#viwe#relatable#exploreindia#relationshipquotes#reelkarofeelkaro#reelsolve#writer#lovereel#motivationlife#motivationalquotes#exploreing#explorepage#brokenheart#sayari#feelitreelit#reelslovers#exploreindonesia#exploreindia#100kfollowers#instagram#fashion#foryou#viralreels