How To Use: '@dataclass' In Python (Tutorial 2023)

preview_player
Показать описание
Here's a quick guide on how you can use dataclasses in Python, and how they help us avoid a lot of boilerplate code.

▶ Become job-ready with Python:

▶ Follow me on Instagram:
Рекомендации по теме
Комментарии
Автор

That tidbit about "variables with default values must come after the ones without them", just explained a big problem I was having. Thank you!

thepackbot
Автор

Very interesting, and cleanly presented. Nice.
It is really good to have the "why" as well as the "how"

adrianbratt
Автор

Thanks for this. As I was watching and working on a selenium web scraping script I realized I could make a config dataclass to store all the css_selectors / xpaths I need for this script!

FrocketGaming
Автор

your explaination is very helpful for understanding the question 'why we need to do that ', and i like your explaination for reading a json file to an object. Thank you very much for this good video.

pankuang-qk
Автор

Thank you. Very clear like your udemy couse ;)

davidl
Автор

You could have used two asterix operators to insert json in your person class
'bob = Person(**json)'

velicihanates
Автор

Great video as always! Have you by any chance made a video about Pydantic (couldn't find it), or are you maybe planning to?

chromery
Автор

How do data classes compare to pydantic third-party library?

MathewGuest
Автор

'banana.calories = 69, i mean, 60' 😂

developer_anonymous
Автор

can we implement linked lists using dataclass?

aryandatla
Автор

Is it better to use that for data or some dict? For example, It seem that I won't be able to get "keywords".

Also, there's a difference between __slots__ and slots=True, which is that you can use default value with the new method.

NoidoDev
Автор

Nice! Named tuple vs dataclass for the next video?

kamurashev
Автор

It's important to talk about __post_init__ because real code WILL need it, dataclass cannot do all the __init__ most times.

smanzoli
Автор

bob = Person(**json)
print(bob)
>>> Person(name='Bob', age='30', job='Salesman', friends=['Mario', 'Luigi'])

MrGeordiejon
Автор

I just wanted to take a moment to express my sincere appreciation for your exceptional explanations and the engaging speed at which you communicate. Your clarity and enthusiasm truly stand out, making learning from you an absolute pleasure. Thank you for your dedication and talent—I genuinely admire the way you convey information

jeyosman
Автор

I'm learning python... bob= Person(**json) is better?

lostsoul
Автор

Do u have a course… or mentoring program

SanwicklithMkalinga-gh
Автор

Don't forget the dataclasses.Field object...can be very useful when dealing with telemetry.
There's also the "astuple" method that is attached to the class.

DrDeuteron
Автор

bob = Person(json['name'], json['age'], json['job'], json['friends'])
why not use this instead?
bob = Person(**json)

nargileh
Автор

Why are you teaching people how to use me?

Timmie_Tudor