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

Резултати

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

Пребарај: #crank

当前筛选 #crank清除筛选
Libreware

@libreware · Post #1007 · 05.11.2021 г., 00:54

We just pushed the V1.2 of the Beechat Crank to our GitHub @beechatnetwork2 Beechat Crank is a human-powered, open-hardware, fully-waterproof, electricity generator. The project was born out of the need to power electronics in all off-grid scenarios. We needed a way to power our devices in all weather conditions, and making a human-powered generator meant that problem could be solved. When we looked for a solution, we didn't find what we were looking for, so we decided to make it, and make it open source! https://github.com/BeechatNetworkSystemsLtd/BeechatCrank/ Features High power (3A) USB-C IPX8 output 18650 3600 mAh battery (LG M36) Charging time of 4 hrs 24 min. to full charge with 10% efficiency loss at 4.5 Watts. Overcharge protection Parts Beechat Crank is composed of the main device, which we call the Heart. It contains the battery, the generator and all the electronics (the handle is detachable) The Pedal Case is an assembly which the Heart can be attached in. which dramatically speeds up the charging from 2.5 hours to 25-30 minutes. This is achieved with reduction gears to, with the same revolutions per minute, generate more electricity. Generator part We have chosen the 35L048B1B motor with a mass of 88 grams, giving us us 450 mA for each phase of the coil and works at 5V. The wire leads are connected via female Molex connectors to the charging PCB board. New modifications: * Added a Molex type connector to the PCB to connect the motor. * The Zener diodes were changed, by means of a rectifier bridge. * A new and improved Texas Instruments brand battery management chip was selected. * Added a boost converter to allow different voltage batteries. * New Portescap brand two-phase generator with 90% efficiency and peak power of 4.5 Watts was selected. #crank#beechat

Видеотека 📼

@videotekashow · Post #14048 · 26.07.2025 г., 18:17

«Вообще, фильм «Карты, деньги, два ствола» был единственной причиной, по которой я поменял профессию». Джейсону Стэйтему сегодня исполнилось 58 лет. #ВИДЕОТЕКА #JasonStatham #LockStockAndTwoSmockingBarrels #Snatch #TheTransporter #Crank #TheExpendables #KillerElite #Safe #Parker #WrathOfMan #AWorkingMan