@Marwa_OsmanLB · Post #3194 · 11.09.2024 г., 13:28
Trump’s absurdity knows no bounds, and this presidential debate saw what many argued was a failure for the former president. #Trump#USelections#debates#elections2024
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
Пребарај: #uselections
@Marwa_OsmanLB · Post #3194 · 11.09.2024 г., 13:28
Trump’s absurdity knows no bounds, and this presidential debate saw what many argued was a failure for the former president. #Trump#USelections#debates#elections2024
@hkdmovement · Post #7914 · 29.11.2024 г., 11:06
美國國會屬下的「美中經濟暨安全檢討委員會」(USCC)於周二(19日)向國會提交2024年報告,涵蓋中美經貿關係、台灣及香港等議題。報告指出,《基本法》23條的立法進一步為港府提供打壓異見的法律工具,香港的法治正受到威脅,法院隨23條的實施被武器化,甚至成為協助俄羅斯等國逃避制裁的中轉站。 #23條立法#USCC#中美角力#美國大選 On Tuesday (19th), the U.S.-China Economic and Security Review Commission (USCC) submitted its 2024 report to Congress, addressing U.S.-China economic relations, Taiwan, and Hong Kong. The report mentions that the implementation of Article 23 of the Basic Law provides the Hong Kong government with legal tools to suppress dissent, threatening the rule of law. It also asserts that Hong Kong has become a transit point for aiding countries like Russia in evading sanctions. #Article23#USCC#USChinaTensions#USElections
@FFC_official_channel · Post #224 · 31.08.2024 г., 23:58
This election is not just about what happens within U.S. borders—it’s about the lives of millions around the globe. When you vote, you’re making a statement about where America stands on human rights. History has shown us that you cannot negotiate with leaders who offer nothing but empty promises. Kamala Harris herself said, "Never let anyone tell you who you are. Show them who you are." Well, the Biden-Harris administration has shown us who they are. For ten months, they’ve done nothing but fund the annihilation of Gaza and the West Bank. We cannot accept these empty words when hundreds of thousands of lives are at risk. It’s time to demand real action, not just lip service. Sign the petition to enact an arms embargo on Israel, spread the truth in your community, and mobilize for the sake of humanity. Take Action Now: 🖋️ Sign the Petition: Not Another Bomb! Demand an arms embargo to stop the genocide (in our stories) 📰 Stay Informed: Join the Uncommitted Movement and tell Kamala Harris to stand on the right side of history. Sign up for updates. 🗣️ Spread the Word: Distribute flyers, educate your community, and support candidates who truly stand for human rights. #KillerKamala#BidenHarris#USElections#DNC#ActForGaza#EndTheOccupation#NoMoreEmptyPromises#FreeGaza#FreePalestine#PermanentCeasefire#UNSecurityCouncil#GlobalImpact#FFC#FreedomFlotilla