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

Резултати

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

Пребарај: #cartography

当前筛选 #cartography清除筛选
Amazing Geography 🌍

@amazingeo · Post #683 · 06.04.2026 г., 20:31

🌍 The oldest known map carved on stone was found in Europe and dates back over 4,000 years. It shows a planned landscape with fields and waterways carefully etched by early mapmakers. ✨ #cartography⚡#history⚡#mapping⚡#geography⚡#nature⚡#earth 👉subscribe Amazing Geography 👉more Channels ​

Amazing Geography 🌍

@amazingeo · Post #640 · 18.02.2026 г., 20:31

🌍 Modern cartographers use remote sensing from satellites to create digital maps so detailed they can track changes in forests, cities, and coastlines within days of new data. ✨ #cartography⚡#mapping⚡#satellites⚡#geography⚡#nature⚡#earth 👉subscribe Amazing Geography 👉more Channels ​

Amazing Geography 🌍

@amazingeo · Post #600 · 29.01.2026 г., 12:31

🌍 Early world maps placed Jerusalem at the center, with Asia, Europe, and Africa shown as a T-shape around it. These symbolic "T-O" maps reveal how medieval people viewed the world’s layout. ✨ #cartography⚡#history⚡#mapping⚡#geography⚡#nature⚡#earth 👉subscribe Amazing Geography 👉more Channels ​

Amazing Geography 🌍

@amazingeo · Post #415 · 25.10.2025 г., 20:31

🌍 The first aerial photograph used for mapping was taken from a hot air balloon over Paris in 1858. This breakthrough marked the start of modern cartography using images from above. ✨ #cartography⚡#mapping⚡#history⚡#geography⚡#nature⚡#earth 👉subscribe Amazing Geography 👉more Channels ​

Amazing Geography 🌍

@amazingeo · Post #377 · 15.10.2025 г., 20:31

🌍 The biggest map ever made is the modern digital world map stored by satellites. Billions of points are updated daily, letting scientists watch Earth’s surface change almost in real time. ✨ #cartography⚡#satellites⚡#mapping⚡#geography⚡#nature⚡#earth 👉subscribe Amazing Geography 👉more Channels ​

Amazing Geography 🌍

@amazingeo · Post #146 · 30.08.2025 г., 20:12

🌍 In 2000, the complete first digital map of Earth—called the SRTM—was created from space using radar. It captured mountain heights and landscape details for over 80% of Earth’s land. ✨ #mapping⚡#cartography⚡#satellites⚡#geography⚡#nature⚡#earth 👉subscribe Amazing Geography🌍 ​

Amazing Geography 🌍

@amazingeo · Post #561 · 07.01.2026 г., 12:31

🌍 The Winkel Tripel projection is now widely used for world maps because it balances area, shape, and distance better than older methods, reducing distortion across continents and oceans. ✨ #cartography⚡#mapprojection⚡#geography⚡#nature⚡#earth 👉subscribe Amazing Geography 👉more Channels ​

Amazing Geography 🌍

@amazingeo · Post #339 · 06.10.2025 г., 15:31

🌍 The first known use of contour lines on a map appeared in 1584, showing the depth of water in the Netherlands. This method is still used today to show elevation and terrain on modern maps. ✨ #cartography⚡#elevation⚡#history⚡#geography⚡#nature⚡#earth 👉subscribe Amazing Geography 👉more Channels ​

Amazing Geography 🌍

@amazingeo · Post #184 · 06.09.2025 г., 00:12

🌍 Some ancient Polynesian maps were made with sticks and shells, showing ocean swells and island positions. These unique charts helped navigators cross vast distances without modern tools. ✨ #cartography⚡#navigation⚡#history⚡#geography⚡#nature⚡#earth 👉subscribe Amazing Geography🌍 ​

Amazing Geography 🌍

@amazingeo · Post #64 · 17.08.2025 г., 09:12

🌍 In 1972, the first Landsat satellite began photographing Earth's surface from space, fueling a new era of digital mapping and revealing real-time changes in forests, cities, and coastlines. ✨ #cartography⚡#satellite⚡#mapping⚡#geography⚡#nature⚡#earth 👉subscribe Amazing Geography🌍

Amazing Geography 🌍

@amazingeo · Post #258 · 18.09.2025 г., 09:12

🌍 The first map to show the Americas as a separate continent was made by German cartographer Martin Waldseemüller in 1507. It’s where the name “America” first appeared on a world map. ✨ #cartography⚡#history⚡#discovery⚡#geography⚡#nature⚡#earth 👉subscribe Amazing Geography🌍 ​

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