@ncdcgov · Post #4100 · 24.11.2023 г., 16:31
⏳Live In 30 minutes Join the discussion on: “Supergerms and the Future of Infection: What can I do?” 🔗bit.ly/LearnWithDRASA7 #WAAW2023#WorldAMRAwarenessWeek
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
Пребарај: #waaw2023
@ncdcgov · Post #4100 · 24.11.2023 г., 16:31
⏳Live In 30 minutes Join the discussion on: “Supergerms and the Future of Infection: What can I do?” 🔗bit.ly/LearnWithDRASA7 #WAAW2023#WorldAMRAwarenessWeek
Hashtags
@ncdcgov · Post #4096 · 23.11.2023 г., 11:44
#Antimicrobials are becoming less effective against common infections in animals & humans. 🚫 Do not self-medicate ✅ Visit a healthcare professional when sick Everyone has a role to play to ensure #antimicrobials continue to work. #AMR#WAAW2023
Hashtags
@ncdcgov · Post #4101 · 25.11.2023 г., 10:11
Antimicrobials play a vital role in fighting infectious diseases across humans, animals, and plants. However, their effectiveness is diminishing, leading to a global crisis known as #AntimicrobialResistance (AMR). Let’s raise awareness, promote responsible use, and work together to combat AMR. #WAAW2023#WorldAMRAwarenessWeek
@ncdcgov · Post #4086 · 20.11.2023 г., 12:18
Every year, the National Antimicrobial Resistance Technical Working Group joins the global community to raise awareness of the dangers of misuse or overuse of #antimicrobials. Fighting #AMR is a global endeavour that must be addressed through a #OneHealth approach as evident in this year's theme of #WAAW2023: ‘Preventing #AntimicrobialResistance together” 🔗Press Release https://ncdc.gov.ng/news/504/nigeria-joins-the-global-community-to-commemorate-world-antimicrobial-awareness-week-%28waaw%29
@ncdcgov · Post #4099 · 24.11.2023 г., 14:57
As an individual, what can you do to prevent #Antimicrobial Resistance? Our #AMR programme manager @beeodune will be live alongside other panellists on @drasatrust's @XSpaces discussion to speak on: “Supergerms and the Future of Infection : 🗓️ Today, 24th November 🕙6:00 PM 🔗Join the conversation via: http://bit.ly/LearnWithDRASA7 #WAAW2023#WorldAMRAwarenessWeek