Python Data Classes - simpler and more Pythonic code!

preview_player
Показать описание
☕️ 𝗕𝘂𝘆 𝗺𝗲 𝗮 𝗰𝗼𝗳𝗳𝗲𝗲:
To support the channel and encourage new videos, please consider buying me a coffee here:

This video looks at Python dataclasses, and how you can use them to create simpler and cleaner code. We'll also look at default values, default factories, and frozen (immutable) dataclasses.

𝗦𝗼𝗰𝗶𝗮𝗹 𝗠𝗲𝗱𝗶𝗮:

📚 𝗙𝘂𝗿𝘁𝗵𝗲𝗿 𝗿𝗲𝗮𝗱𝗶𝗻𝗴 𝗮𝗻𝗱 𝗶𝗻𝗳𝗼𝗿𝗺𝗮𝘁𝗶𝗼𝗻:

#python #programming #datascience #dataanalytics
Рекомендации по теме
Комментарии
Автор

Thank you for the great explanation, you have a talent for make concepts clear and easy to understand.

zanzoid
Автор

Thank you for all the hard work that you put in making these videos. But is it safe to assume that you have given up on the idea of making a GeoDjango series?

banka
Автор

Similar to C# props, constructor then methods

RandyAinsworth-txvn
Автор

Will this eliminate the the need to use SQLAlchemy?

Dibakash
Автор

This, in my opinion, is walking a fine line between being too trivial to warrant a new feature (writing the init-method takes only few lines of code) and having such specific features that it would be simpler to just implement them in a specific init-function.

One specific issue I can see is writing code where the default-factory is in practice mandatory. As in code where you are never expected to provide this argument. Like in the case of the UUID, or a hash: the only way to properly provide the argument is to do exactly what the default_factory does. In practice this is a mandatory_factory.

Arguably this is very usable in a project with a lot of simple datatypes. In such case hiding the init-functions is valuable, freezing the instances is valuable, and easily omit data from repr.

catcatcatcatcatcatcatcatcatca
Автор

why are you using dataclasses mate and not pydantic?

akagamishanks
join shbcf.ru