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

Резултати

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

Пребарај: #aviationfuel

当前筛选 #aviationfuel清除筛选

የአውሮፓ ኅብረት የአውሮፕላን ነዳጅ እጥረት ለመቋቋም የሚያስችል ዕቅድ ይፋ ሊያደርግ ነው ************************** በመካከለኛው ምስራቅ አሜሪካ እና እስራኤል ከኢራን ጋር የገቡበት ጦርነት በአውሮፓ አየር መንገዶች ላይ የነዳጅ አቅርቦት እጥረት ስጋት ደቅኗል። ይህንን ችግር ለመቅረፍም የአውሮፓ ኅብረት ልዩ የመፍትሄ ዕቅድ እያዘጋጀ መሆኑን የህብረቱ ባለሥልጣናት መግለጻቸውን ሮይተርስ ዘግቧል። ኅብረቱ የነዳጅ ማጣሪያዎችን የማምረት አቅም ለማሳደግና የአቅርቦት ሰንሰለቱን ለማረጋጋት የሚያስችል ረቂቅ ሰነድ እያዘጋጀ ይገኛል። የአውሮፓ ኮሚሽን ከሚቀጥለው ወር ጀምሮ በአባል ሀገራቱ የሚገኙ የነዳጅ ማጣሪያዎችን የማምረት አቅም በዝርዝር የሚያጠና ሲሆን፣ ያሉትን ማጣሪያዎች ሙሉ በሙሉ ጥቅም ላይ እንዲውሉ የሚያስችሉ እርምጃዎችን ይወስዳል ተብሎ ይጠበቃል። አውሮፓውያን 75 በመቶ የአውሮፕላን ነዳጅ የሚያስመጡት ከመካከለኛው ምስራቅ በመሆኑ፣ ኅብረቱ አሁን ላይ የገጠመውን እጥረት ለመቅረፍ አማራጭ መፍትሄዎችን ለመመልከት ተገዷል። ዓለም አቀፉ የኢነርጂ ኤጀንሲ (IEA) በበኩሉ አውሮፓ ከመካከለኛው ምስራቅ የሚያገኘውን ነዳጅ ቢያንስ በግማሽ መተካት ካልቻለ፣ እስከ ሰኔ ወር ድረስ የክረምቱን የጉዞ ወቅት የሚያስተጓጉል ከፍተኛ እጥረት ሊያጋጥመው እንደሚችል ስጋቱን ገልጿል። በመሀመድ ፊጣሞ Ethiopian Broadcasting Corporation #Europe#AviationFuel#EnergyCrisis#IEA#EBC

Crypto M - Crypto News

@CryptoM · Post #64535 · 09.04.2026 г., 06:35

🚀 U.S. March CPI Expected to Rise Amid Ongoing Iran Conflict The market widely anticipates that the U.S. Consumer Price Index (CPI) for March will increase by 3.4%, surpassing last month's 2.4%, marking the largest year-on-year rise in two years. According to Jin10, during past oil market shocks, the most likely commodities to see price hikes include aviation fuel, steel, aluminum, natural gas, fertilizers, and plastics. Industries reliant on these materials are already feeling the strain. The ongoing Iran conflict, which has lasted several weeks, has shifted concerns from the initial oil price surge to the compounded effects of a prolonged conflict. For many economists, the most alarming aspect is not the immediate issues but the "aftershocks" that may emerge months or even years later. JPMorgan's CEO has referred to inflation as a potential "fly in the ointment" that could undermine stock market returns in 2026. Harvard University professor and former IMF chief economist Ken Rogoff recently discussed an overlooked impact of the war: the increased military spending's effect on the already strained U.S. budget deficit. He noted the risk of soaring bond yields, which could harm the stock market and affect U.S. affordability. Rogoff also mentioned that the current supply disruptions caused by the Iran conflict are sufficient to keep oil prices elevated for a year. #USCPI#inflation#IranConflict#oilprices#aviationfuel#steel#aluminum#naturalgas#fertilizers#plastics#economicimpact#stockmarket#JPMorgan#budgetdeficit#militaryspending#bondyields#HarvardEconomist#supplydisruptions#USaffordability