@sgmrt · Post #1691 · 07.04.2023 г., 06:31
[CCL]: If you are at #DhobyGhaut and heading towards #PayaLebar, you may take the NSL and EWL instead. Free regular bus and free bridging bus services are still available. - SMRT
Hashtags
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
Пребарај: #dhobyghaut
@sgmrt · Post #1691 · 07.04.2023 г., 06:31
[CCL]: If you are at #DhobyGhaut and heading towards #PayaLebar, you may take the NSL and EWL instead. Free regular bus and free bridging bus services are still available. - SMRT
Hashtags
@sgmrt · Post #1894 · 22.03.2024 г., 02:35
[CCL] UPDATE: Normal train service has resumed. Free regular bus service between #PayaLebar and #DhobyGhaut / #MarinaBay has ceased. - SMRT
Hashtags
@sgmrt · Post #1893 · 22.03.2024 г., 02:19
[CCL] UPDATE: Additional 20 mins train travel time from #PayaLebar to #DhobyGhaut / #MarinaBay, due to a train fault. Free regular bus service is available between #PayaLebar and #DhobyGhaut / #MarinaBay. - SMRT
Hashtags
@sgmrt · Post #1892 · 22.03.2024 г., 01:55
[CCL] UPDATE: Additional 30 mins train travel time from #PayaLebar to #DhobyGhaut / #MarinaBay, due to a train fault. Free regular bus service are available between #PayaLebar and #DhobyGhaut / #MarinaBay. - SMRT
Hashtags
@sgmrt · Post #1884 · 08.02.2024 г., 03:14
[CCL] UPDATE: Due to a signal fault, please add additional 20 minutes travel time between #DhobyGhaut, #MarinaBay and #PayaLebar. Free regular bus services are available between #DhobyGhaut, #MarinaBay and #PayaLebar. - SMRT
Hashtags
@sgmrt · Post #1883 · 08.02.2024 г., 02:19
[CCL] UPDATE: Due to a signal fault, please add additional 15 minutes travel time between #DhobyGhaut, #MarinaBay and #PayaLebar. Free regular bus services are available between #DhobyGhaut, #MarinaBay and #PayaLebar. - SMRT
Hashtags
@sgmrt · Post #1745 · 23.06.2023 г., 21:19
[CCL] UPDATE: Normal train services between #DhobyGhaut / #MarinaBay and #PayaLebar have resumed. - SMRT
Hashtags
@sgmrt · Post #1744 · 23.06.2023 г., 16:33
[CCL] UPDATE: Train services have ended between #DhobyGhaut / #MarinaBay and #PayaLebar. Free regular bus and bridging bus have ceased. - SMRT
Hashtags
@sgmrt · Post #1736 · 23.06.2023 г., 14:19
[CCL] : [Update] Additional 30mins train travel time between #DhobyGhaut / #MarinaBay and #PayaLebar due to a signal fault. Free regular bus services are available between #DhobyGhaut / #MarinaBay to #PayaLebar. Our engineers are still looking into the fault. - SMRT
Hashtags
@sgmrt · Post #1735 · 23.06.2023 г., 14:03
[CCL] : Additional 30mins train travel time between #DhobyGhaut / #MarinaBay and #PayaLebar due to a signal fault. Free regular bus services are available between #DhobyGhaut / #MarinaBay to #PayaLebar. - SMRT
Hashtags
@sgmrt · Post #1734 · 23.06.2023 г., 13:18
[CCL] CLEARED: Train services between #DhobyGhaut /#MarinaBay and #PayaLebar have resumed. Free regular bus & free bridging bus svcs have ceased. - SMRT
Hashtags
@sgmrt · Post #1732 · 23.06.2023 г., 13:03
[CCL] : Additional 30mins train travel time between #DhobyGhaut / #MarinaBay and #PayaLebar due to a signal fault. Free Regular Bus is available between #DhobyGhaut / #MarinaBay and #PayaLebar. - SMRT
Hashtags