@sgmrt · Post #2473 · 01.09.2025 г., 01:19
[CCL] UPDATE: Train services between #Promenade and #MarinaBay have resumed their scheduled operations. Free regular bus services have ceased. - 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
Пребарај: #marinabay
@sgmrt · Post #2473 · 01.09.2025 г., 01:19
[CCL] UPDATE: Train services between #Promenade and #MarinaBay have resumed their scheduled operations. Free regular bus services have ceased. - SMRT
Hashtags
@sgmrt · Post #2472 · 01.09.2025 г., 01:14
[CCL] UPDATE: Train services are progressively resuming their scheduled service between #Promenade and #MarinaBay. - SMRT
Hashtags
@sgmrt · Post #2471 · 01.09.2025 г., 01:04
[CCL] UPDATE: Due to a train fault, train service is expected to recover its scheduled service in 15 minutes between #Promenade and #MarinaBay. We apologise for any inconvenience caused. Please approach our station staff if you need further assistance. - SMRT
Hashtags
@sgmrt · Post #2470 · 01.09.2025 г., 00:54
[CCL] Update: Free regular bus services are available between #Promenade and #MarinaBay. You may download an e-Travel Chit as proof of your travel at https://bit.ly/39HsrAl if your journey has been affected. - SMRT
Hashtags
@sgmrt · Post #2468 · 01.09.2025 г., 00:49
[CCL]: Due to a train fault, there is no train service between #MarinaBay and #Promenade. Free regular bus services are available between #MarinaBay and #Promenade. https://bit.ly/3JHKRD2 - SMRT
Hashtags
@sgmrt · Post #1468 · 20.06.2022 г., 05:58
[CCL] UPDATE: Additional 10mins train travel time from #Promenade to #MarinaBay. We are working to recover service. - SMRT
Hashtags
@URASingapore · Post #910 · 24.07.2024 г., 10:00
Singapore’s hot weather can be a bother if you take a stroll at Marina Bay. But with our solar-powered breeze shelters strategically placed along the promenade, you don’t need no Oppas to shelter you from the heat! 🌬 #UrbanDesign#DiscoverSingapore#MarinaBay
@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