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

Резултати

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

Пребарај: #hunting

当前筛选 #hunting清除筛选

Today I have a little lesson about hunting knives for you. Those knives are free and easy to get, require just little storage space and require almost no maintenance. In any case it will be good to have such a set. On the right side there is a knife you need first after bringing down your prey. (As an example we will use deer.) Use the big sharp blade to cut the biggest parts and the little hooked blade on the back to open the skin on thorax and abdomen. Next you would need the middle knife for making smaller, more precise cuts. Also for smaller prey like rabbits this type is useful to precisely cut around lymph nodes. The tool on the left is a dedicated bonesaw to open the ribcage from the front, which is helpful in any case to reach the organs. After usage these tools need to be cleaned with water. (In some cases you would need soap, for example when you accidentally cut intestines or rumen. #survival#hunting#tools @EuropeanTribalism

Interesting Planet 🌍

@interesting_planet_facts · Post #573 · 16.08.2025 г., 20:22

🌎 The bolas spider swings a sticky silk “lure” scented like female moths to attract unsuspecting mates—then snags them midair in a single swoop! ✨ #spider⚡#mimicry⚡#hunting 👉subscribe Interesting Planet

Airdrop Presents 🗽

@airdrop_presents · Post #803 · 07.03.2022 г., 08:20

@MetaShooter_gg is running a LEGENDARY $100,000 MYSTERY BOX campaign! Join our gleam competition: 🔗https://gleam.io/Op3lz/metashoote 📃 Follow all the rules and tag your friends to join the airdrop campaign! #NFT#ADA#Metaverse#Giveaway#P2E#Cardano#playtoearn#hunting#airdrop#playtoearn Website | Twitter | Telegram | Announcements | Discord | Medium | Instagram | Youtube | TikTok | Reddit | Facebook

VIP_影视分享

@WangZhuanZhan · Post #34529 · 28.10.2024 г., 14:09

L-l猎l头t- 猎头 (1982) 直达链接:https://pan.quark.cn/s/7ef305b73e40 #猎头#再见江湖 #豪情杀手#夺命枪手 #Hunting Head #Long Goodbye #飚情杀手 链接:https://link3.cc/sf_com #电影#爱情#内地#80年代