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

Резултати

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

Пребарај: #türkiye

当前筛选 #türkiye清除筛选

#Türkiye continues to support the Zionist regime See the published pictures of Turkish agricultural products in the port of Haifa, Israel Türkiye Siyonist rejimi desteklemeye devam ediyor. İsrail'in Hayfa limanında Türk tarım ürünlerinin yayınlanan resimlerini görün https://t.me/YediotNewsChat

Hashtags

Ankara Rus Evi

@ankara_rusevi · Post #3445 · 24.11.2024 г., 17:38

1️⃣1️⃣1️⃣1️⃣ Russian Experts Conclude Their Visit to Ankara🇹🇷 From November 20 to 22, Russian experts visited Ankara as part of a program organized by the Primakov Center in collaboration with the Russian House in Ankara. The delegation included representatives from IMEMO, Institute of Oriental Studies RAS, MGIMO, MSU,RUDN, and other institutions. Key Highlights: 🔵 The visit lasted 3️⃣ days. 🔵 The Russian delegation visited 3️⃣ academic and research centers in Ankara: ORSAM, SDE, and the Faculty of Political Science at Ankara University. 🔵 Experts participated in 3️⃣ round tables and 1️⃣ conference. 🔵 Topics discussed included resolving conflicts in the Middle East, the role of Eurasianism in the region, and humanitarian cooperation between Turkey and Russia. Сountless glasses of black tea and cups of ayran were also enjoyed during the visit! 🔵 Find more details about the working trip to Ankara on our website. #türkiye 1️⃣1️⃣1️⃣

Hashtags

StartupBase

@startupbaseuz · Post #5088 · 28.11.2024 г., 12:42

#meeting#Türkiye 👍 IT Park Uzbekistan Turkiya delegatsiyasi bilan hamkorlik istiqbollarini muhokama qildi 27-noyabr kuni "Ostim" sanoat zonasi boshqaruvi raisi boshchiligida Turkiya kompaniyalarining O'zbekistonga rasmiy tashrifi doirasida uchrashuv bo‘lib o‘tdi. Tashrifdan ko‘zlangan maqsad yuqori texnologiyalar va innovatsiyalar sohasida tajriba almashish hamda O‘zbekiston va Turkiya kompaniyalari o‘rtasida strategik hamkorlikni yo‘lga qo‘yishdan iborat. Turkiya delegatsiyasi vakillari turkiyalik hamkorlarda katta qiziqish uyg‘otgan startaplar, dasturiy ta‘minot ishlab chiquvchilar va IT-kompaniyalarni qo‘llab-quvvatlashga qaratilgan loyiha va tashabbuslar bilan tanishdi. 🕸Batafsil bizningveb-saytimizda ______ 👍 IT PARK Uzbekistan Discusses Prospects for Cooperation with a Turkish Delegation On November 27, a meeting was held as part of the official visit of Turkish companies to Uzbekistan, led by the Chairman of the Board of the industrial zone "Ostim." The purpose of the visit was to exchange expertise and establish strategic partnerships between Uzbek and Turkish companies in the field of high technology and innovation. During the meeting, Turkish delegation representatives were introduced to projects and initiatives aimed at supporting startups, software developers, and IT companies in Uzbekistan, which sparked significant interest among Turkish partners. 🕸Read more on ourwebsite Telegram | Instagram | Facebook | Youtube | LinkedIn

Addis Standard

@addisstandardeng · Post #21407 · 15.02.2026 г., 07:50

#Türkiye’s President Erdoğan to visit #UAE, #Ethiopia next week Addis Abeba – Recep Tayyip Erdoğan is scheduled to visit the United Arab Emirates (UAE) and Ethiopia next week as part of a two-nation tour according to Türkiye’s Communications Bureau. The bureau said President Erdoğan will first travel to Abu Dhabi on Monday, where he is expected to meet with Sheikh Mohammed bin Zayed Al Nahyan. Discussions are anticipated to focus on expanding cooperation between Türkiye and the UAE, as well as regional and global developments. On Tuesday, President Erdoğan will arrive in Addis Abeba at the invitation of Ethiopia’s Prime Minister, Abiy Ahmed. The Communications Bureau noted that several agreements and documents whose negotiations have been finalized are expected to be signed during the visits. The announcement comes amid heightened regional attention over the ongoing conflict in neighboring Sudan. https://x.com/addisstandard/status/2022941119755981206?s=46&t=ofAzVW8-64dDK-xsjodCGA

В Турции найдены запасы редкоземельных элементов в 694 млн тонн, — Эрдоган Это второй по величине показатель в мире после Китая. Разработка и добыча этих запасов может вывести Турцию в число пяти крупнейших мировых производителей редкоземельных элементов. #Türkiye#türk@turkicfront88

AES INFO

@aesinfos · Post #2015 · 07.12.2024 г., 22:07

#AESinfo | #Mali🇲🇱⚡️🇹🇷#Türkiye Le chef de la Diplomatie malienne, SEM Abdoulaye Diop rencontre Hakan Fidan au #Qatar. Dans le cadre du Forum de Doha, Son Excellence Monsieur Abdoulaye DIOP, Ministre des Affaires étrangères et de la Coopération internationale a eu un entretien fructueux avec Son Excellence Monsieur Hakan Fidan, Ministre des Affaires étrangères de la Türkiye sur des questions bilatérales et multilatérales d'intérêt commun, en marge de son séjour au #Qatar. Source : @MaliMaeci

ПретходнаСтраница 1 од 5Следна