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

Резултати

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

Пребарај: #rats

当前筛选 #rats清除筛选
Crypto

@signal_bitcoins · Post #2567 · 29.01.2024 г., 13:20

#RATS is dropping in a bearish channel on 4H time frame,we are waiting for breakup from the supply zone and ceiling of the bearish channel..✨ ❄️@signals_bitcoin_crypto❄️ ❄️@Shadow_support0o❄️

Hashtags

Crypto

@signal_bitcoins · Post #2463 · 22.01.2024 г., 10:41

#RATS has falling wedge pattern on 4H Time frame,we expect it will have a good pump from the support zone in near future 💎 ❄️@signals_bitcoin_crypto❄️ ❄️@Shadow_support0o❄️

Hashtags

Crypto

@signal_bitcoins · Post #2275 · 11.01.2024 г., 12:31

#RATS has a falling wedge pattern on 4H Time frame,in the case of breakup we will see huge pump again 💎 ❄️@signals_bitcoin_crypto❄️ ❄️@Shadow_support0o❄️

Hashtags

Crypto

@signal_bitcoins · Post #2083 · 29.12.2023 г., 07:36

#RATS bounced back from the Trendline on 2H Time frame,we expect it will pump from here until the next level 🚀 ❄️@signals_bitcoin_crypto❄️ ❄️@Shadow_support0o❄️

Hashtags

TokenPocket

@tokenpocket_channel · Post #1033 · 21.12.2023 г., 05:33

✨ Unlock simplicity in #BRC20 transfer! 🚀Now, easily transfer your #BRC20 assets in just ONE step! 🔄 Inscribe and transfer seamlessly for a more efficient and convenient experience. 👉https://tokenpocket.pro Ready to experience seamless #BRC20 transactions? Follow the tutorial: 👉https://help.tokenpocket.pro/en/wallet-faq-en/btc-wallet/brc20 #Sats#ordi#RATS#Inscriptions 【Details】https://twitter.com/TokenPocket_TP/status/1737707370523005390 【Powered By】Crypto Box

TokenPocket

@tokenpocket_channel · Post #1025 · 19.12.2023 г., 03:22

🟧 TokenPocket Now Fully supports BRC-20! #BRC20 ✅#BRC20 tokens deposit, withdrawal, and token price display. ✅ Transfer your #BRC20 in one single transaction (Inscribe and Transfer in one step) 🆕We just released the iOS new version 🔺2.1.9🔺(TP Wallet) and Android new version 🔺1.9.5🔺. Upgrade your TP Wallet/TokenPocket and discover the #BRC20#Inscriptions world with us! 👉https://www.tokenpocket.pro/ #Sats#ordi#RATS#Inscriptions 【Details】https://twitter.com/TokenPocket_TP/status/1736949473048420555 【Powered By】Crypto Box

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