This Is Why Python Data Classes Are Awesome

preview_player
Показать описание

Data classes in Python are really powerful and not just for representing structured data. In this video, I show you what you can do with dataclasses as well as new capabilities that have been added in Python 3.10.

🔖 Chapters:
0:00 Intro
0:49 What are data classes?
1:37 Explaining the example
4:00 Dataclasses basics
5:45 Assigning default values
8:54 Excluding arguments from the initializer
9:44 Using post_init to generate extra fields
11:25 Private/protected members
11:59 Excluding information from the repr
12:43 Freezing a dataclass
14:59 (new in Python 3.10) kw_only
16:10 (new in Python 3.10) match_args
17:00 (new in Python 3.10) slots
21:30 Final thoughts

#arjancodes #softwaredesign #python
Рекомендации по теме
Комментарии
Автор

Arjan, your ability to explain detail in a structured, easy to follow format is second to none. Thank you for another great tutorial.

sbeau
Автор

One thing to note, when you pass data class "frozen=True", instance is immutable.
So at 13:29 you are actually getting error for search_string which we are trying to change at _post_int_ at object creating not for person name (line 25)
You can not change fields even inside the class even with setter methods.

saketh_s
Автор

I came to Python from C# so I picked up coding quickly. But thinking in python way is harder, so such videos really help me develop python mindset.

hematogeng
Автор

Arjan,
You should seriously consider doing a full fledged Python course from beginner to advance level laden with Projects so we can learn Python the Pythonic way.

vedambala
Автор

Although I like the ability to learn and use Data Classes. All my years of database programming has taught me to use JSON, and Dictionaries as much as possible. Especially in Web Services. The caveat to using Data Classes is that; changing a column type, name or description, or adding or removing columns ends up as a use case/feature ticket for the programmer which can take a bit of time to run through the development cycle. These column changes are guaranteed to happen all the time, in the life cycle of the product. A second problem, is that the code must be completely thrown out, when starting a new product. Using Dictionaries very often can allow these column changes from config files without recompiling or restructuring the code base. Going back to Web Services. Dictionaries can be web requests and responses, in JSON, without translation. This makes for high performance, and easy maintenance in the life cycle of product. It also makes copying and pasting the code directly into other products a possibility.

auroraRealms
Автор

I have an observation. Even if you remove the person.name = "Arjan" and set the dataclass frozen=True you will have a FrozenInstanceError. Because you use the __post_init__ method and the frozen dataclass does NOT allow it ! So you must remove the __post_init__ method if you want to freeze the dataclass and prove that you cannot modify it after initialization.
THANK YOU FOR YOUR AMAZING VIDEOS !

techassets
Автор

This is truly an excellent successor to your earlier video on data classes, bravo!

jordansilke
Автор

This guy really know what he is doing every video I've seen he able to break it down to where even a person new to python can understand

"if you can't explain it simply, you don't understand it well enough." - Albert Einstein

Volcan-kfoz
Автор

Enjoyed this video. Would enjoy more videos on intermediate/advanced python standard library tools and their examples of their intended use cases.

coupmd
Автор

I wasn't even trying to learn about dataclasses...but it came up on my recommended and I watched the entire thing- Got me thinking I should clean up some old code.

equu
Автор

Just like every video from you my knowledge of programming with python is advanced. I really appreciate the content you provide, thank you!

bryan_hiebert
Автор

Working my way through my third LinkedIn Learning (LIL) Python course, all of which claim to teach you the data structures available. Arjan's short video explains a dozen reasons why you want to use dataclass that the LIL courses didn't include. Thank you!

neoporcupine
Автор

@ArjanCodes, great video. I consider myself a casual programmer and have been programming with Python for about 5yrs and absolutely love it. I started programming "casually" in the 80's with C, Pascal, Assembler, then Perl and now Python. I really enjoyed C and Perl, but Python is by far my favorite now. This is the first video I've seen of yours and based on that I just subscribed to your channel. I enjoy your style and explanations and I don't have to play the video at twice the speed waiting for you to get to the point. I'm looking forward to seeing more of your Python videos.

FrankenLab
Автор

This guy is excellent. I've only watched a couple of his videos so far. Planning on watching a few more today.

Clear, concise, accessible. So far, great!

ritzg
Автор

Since we're talking a lot about dataclasses, I wonder would it be great combining with sql database. If we could get a review that would be very helpful!

Cookie-mvhg
Автор

What happened to “explicit is better than implicit” and to “there should be only one obvious way to do something”?

paulorsbrito
Автор

Wow, the most complete tutorial I've seen. Not a single detail has been missed.

mpotane
Автор

The final note about slot was really great.
Thanks

aminramazanifar
Автор

I am 100% gonna use the repr=False option, thank you!

Rebeljah
Автор

Again Arjan, another fantastic video. If I become half the programmer you are I will be lucky. But I just have the love of programming so I will continue to work on improving my knowledge and skill set. So many programmer say just read the Docs, but I learn from examples and the Docs usually have few if not poor examples. So a big part of my improvement will be in thanks to your love of sharing your knowledge. Thank you...

mauisam
join shbcf.ru