@digitalgentop · Post #41 · 21.05.2024 г., 21:22
💰📊In the past 24 hours, Ethereum whales have purchased more than 110,000 ETH valued at $341 million!💵😮 #Cryptoenthusiast #Cryptocurrencies #Cryptowallet
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
Пребарај: #cryptoenthusiast
@digitalgentop · Post #41 · 21.05.2024 г., 21:22
💰📊In the past 24 hours, Ethereum whales have purchased more than 110,000 ETH valued at $341 million!💵😮 #Cryptoenthusiast #Cryptocurrencies #Cryptowallet
@digitalgentop · Post #11 · 21.05.2024 г., 17:43
💰📊In the past 24 hours, Ethereum whales have purchased more than 110,000 ETH valued at $341 million!💵😮 #Cryptoenthusiast #Cryptocurrencies #Cryptowallet
@digitalgentop · Post #241 · 06.06.2024 г., 08:02
⚡️Main news: 🔗Wallet on Telegram enforces new KYC rules, switches provider 🟢 PEPE whale up nearly $5M on investment within a month 💵Next $1 trillion company will be DePIN 📌 Alex Labs rolls out post-exploit recovery plan 💰Bitcoin in 42-day ‘boredom zone’ — traders debate next move #Cryptoanalysis #Cryptoenthusiast #Cryptocurrencies #Cryptowallet
@digitalgentop · Post #240 · 06.06.2024 г., 02:57
❗️Donald Trump found guilty in landmark New York hush-money case 🇺🇸 #Cryptoanalysis #Cryptoenthusiast #Cryptocurrencies #Cryptowallet
@digitalgentop · Post #230 · 04.06.2024 г., 03:02
💵Gemini returns $2.18B to Earn users following 18-month withdrawal freeze ⌛ #Cryptoanalysis #Cryptoenthusiast #Cryptocurrencies #Cryptowallet
@digitalgentop · Post #224 · 02.06.2024 г., 16:01
☄️ZKasino gives investors 72-hour window to get back deposited ETH 💵ZKasino denied it tried to make off with $33 million of investor funds in April and has now opened up a short refund window. #Cryptoanalysis #Cryptoenthusiast #Cryptocurrencies #Cryptowallet
@digitalgentop · Post #213 · 31.05.2024 г., 16:01
🔖Shiba Inu Super Diamond Trader Liquidates Holdings, Followed By A Secret Message 📣 #Cryptoenthusiast #Cryptocurrencies #Cryptowallet #Cryptoeducation #Bitcoinnews