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

Резултати

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

Пребарај: #jungkook

当前筛选 #jungkook清除筛选
Bts.bighitofficial

@OUR_7_PRINCES · Post #115040 · 03.08.2025 г., 22:58

According to @/mkgenie, the president of Michael Jackson's Chinese fanclub, and that had access to the list of recording artists of the MJ tribute project in 2023, Jungkook was one of the renowned singers that would get to sing one of the 10 never-released song written by Michael Jackson along with Bruno Mars, Doja Cat and Sza! #JUNGKOOK •@OUR_7_PRINCES•

Hashtags

Bts.bighitofficial

@OUR_7_PRINCES · Post #114386 · 03.07.2025 г., 02:12

“Yes, Love him! Incredible! His dancing, singing, songs, incredible machine. I love that dude, like he’s incredible” — Omar Rudberg, a Venezuelan-Swedish singer and actor, about #Jungkook #JUNGKOOK •@OUR_7_PRINCES•

Hashtags

Bts.bighitofficial

@OUR_7_PRINCES · Post #115323 · 26.11.2025 г., 00:22

GameSpot, a major American website providing news & reviews about video games, wrote an article about #Jungkook “BTS's Jungkook Is A Streamer Now, Here Are The Games He's Played So Far” https://www.gamespot.com/gallery/btss-jungkook-is-a-streamer-now-here-are-the-games-hes-played-so-far/2900-7286/ #INFO •@OUR_7_PRINCES•

Bts.bighitofficial

@OUR_7_PRINCES · Post #115206 · 13.08.2025 г., 15:27

Famous actor Manny Jacinto said #Jungkook was his bias in a recent interview for Cosmopolitan Q: Recently, a photo of you at a j-hope concert made the internet rounds. Who is your BTS bias? 🗣️ “Jungkook. I was a dancer, and I have this theory. Jungkook apparently trained in Los Angeles when he was younger, and I think we almost crossed paths and trained in the same studio around the same time. I mean, he is, like, eight years younger than me, but I saw videos and pictures of him training at the same studio. And I was like, wait, when was this? And this was around the same time, like, summer of 2012, 2011. I think he’s one of the best dancers on the team. But I also just dig his music.” #INFO •@OUR_7_PRINCES•

123•••89
ПретходнаСтраница 1 од 9Следна