Python Data Classes Are AMAZING! Here's Why

  Рет қаралды 69,028

Tech With Tim

Tech With Tim

Күн бұрын

In this video, you'll discover why data classes are a game-changer for Python developers for simplifying code and enhancing readability.
If you want to land a developer job: techwithtim.net/dev
Skool community for free resources: www.skool.com/software-develo...
Discord server: / discord
🎞 Video Resources 🎞
Docs: docs.python.org/3/library/dat...
⏳ Timestamps ⏳
00:00 | Before Data Classes
01:14 | An Intro To Data Classes
01:47 | How A Data Class Works
04:57 | If You Want To Become A Developer
05:49 | Data Class Example
06:58 | Optional Arguments
07:53 | Default Parameters
10:28 | A Quick Tip - Help()
10:55 | Class Variables
11:39 | Inheritance
14:03 | InitVar
Hashtags
#python
#dataclasses
#programming

Пікірлер: 68
@TechWithTim
@TechWithTim 3 ай бұрын
If you’re serious about becoming a developer check out my program with course career: techwithtim.net/dev
@MrRocka12
@MrRocka12 3 ай бұрын
hey tim is this in the course?
@TechWithTim
@TechWithTim 3 ай бұрын
@@MrRocka12 yes!
@sobi-94
@sobi-94 3 ай бұрын
I've only just started watching this video but I just want to say you're really talented and informative. I think you're excellent at conveying what's going on in a simplified way. I think this is the earliest I've ever been for one of your videos haha. Please keep doing what you're doing for the computer science and data science space! Sending you blessings from the UK☺
@DrDeuteron
@DrDeuteron 2 ай бұрын
I was given a csv file with 524 columns of date times, instrument telemetry, etc...dataclass saved the day...just cut and paste the column header names and let the decorator do the rest. Also put the in-spec limits in the field's metadata along with LaTex strings for y-axis labels. 524...times. data class ftw.
@marktaylor9886
@marktaylor9886 2 ай бұрын
I've been watching old videos, so good to finally see you on VS Code! haha
@rockstarj3
@rockstarj3 2 ай бұрын
Perfect timing for this video. I was able to use it right away in my project.
@repairstudio4940
@repairstudio4940 3 ай бұрын
Oh this is wonderful, thanks Tim! 🎉
@Dot_Starshot
@Dot_Starshot 2 ай бұрын
Man this will be a good and convenient way of reduced my classes code in my current project. Thanks for such good content, and also at the perfect time 😜
@tech_with_the_unknownguy
@tech_with_the_unknownguy 2 ай бұрын
cool video Tim!
@MilahnMartin
@MilahnMartin 3 ай бұрын
Awesome video ! What switches do you have on your keyboard ? Does anyone know ?
@rafacoluccijf
@rafacoluccijf 2 ай бұрын
I am still not conviced. Sure, for small classes with a few fields and logic it might be worth it. But in real world prod code you will have inheritance, polymorphism, logic, dependecies, etc. and you will end up having to implement all those "hacks" you mentioned. Simple classes will be much easier to understand and read and will have probably less overhead. Dont get me wrong, it is a nice tool to have in mind but call it AMAZING is a little too much IMHO. It would be much better if Dataclass just worked without having to implement all those hacks like post_init. I think it is designed to be use as placeholders for data you get from a database for example.
@y2ksw1
@y2ksw1 Ай бұрын
This decorator should be called @classes and inbuilt, without the need of a decorator 😊. Contrarily, with a @boilerplate decorator, that functionality could be then disabled, but I would like to see, how often that is going to be used 😅 It is the missing link for building a fully functional class without being bothered with boilerplate code. Which I believe would be best to not require anyway.
@hennadiiborysov7816
@hennadiiborysov7816 2 ай бұрын
Good topic, please continue
@midhunr3176
@midhunr3176 2 ай бұрын
Thank you keep going
@fr9714
@fr9714 2 ай бұрын
Great tutorial
@user-ov1ps7go4m
@user-ov1ps7go4m 3 ай бұрын
Would you recommend Python/Pygame for aspiring Android Game Developers?
@ezrasamson-ez2mv
@ezrasamson-ez2mv 3 ай бұрын
Hi tim do you know any thing about odoo developers
@rohitkumar34864
@rohitkumar34864 2 ай бұрын
Which theme are you using?
@richardmonteiro8694
@richardmonteiro8694 Ай бұрын
12.30 time line the super().__init__(self.side, self.side) should be super().__init__(self.height, self.width) right?
@Muhaiminul_coding_club
@Muhaiminul_coding_club 3 ай бұрын
this is super cool 😎 😎
@JorgeEscobarMX
@JorgeEscobarMX 12 күн бұрын
Is this video part of a playlist?
@Master_of_Chess_Shorts
@Master_of_Chess_Shorts 2 ай бұрын
I understand the decorator and how useful it is when you are defining a class. You explain really well and your video is edited well. I am not going to use it though. I like to understand code completely and I feel that this approach "hides" potential clarity for the benefit of saving just a few lines of code that originally made the class more readable. It can get complicated if you keep adding parameters like order. Resistance to change, I guess.
@GiiT2024
@GiiT2024 2 ай бұрын
Hello there Tim, am launching 200 days of python code challenge and am glad that you are that person who made me love python, but now tell me if there's away I should approach this 200 days of coding
@jaserogers997
@jaserogers997 2 ай бұрын
Just do it ffs
@helomydestiny8431
@helomydestiny8431 3 ай бұрын
hey , this is quite outside the topic , but anyone know how to fix could not find and load class main ( in java in vscode ) . By the way when i output the small code such as "hi" , "hello world " , it works but when i print a large lines of code , the terminal doesn't give me the output and the output keeps saying could not find and load class main ?
@edwardmacnab354
@edwardmacnab354 3 ай бұрын
go to stack overflow to get beat up and demeaned with a RTFM reply
@CattleRustlerOCN
@CattleRustlerOCN 2 ай бұрын
Try a different name other than main and see if it works
@lukemarshall1892
@lukemarshall1892 2 ай бұрын
Get out of here you're scaring the children
@ssublexff3465
@ssublexff3465 2 ай бұрын
Try reinstalling java dependencies as well as check it in some other IDE just so you know there is not some IDE kind of error.
@agnichatian
@agnichatian Ай бұрын
just hit alt-F4
@englishsimple1052
@englishsimple1052 2 ай бұрын
Hello Tim! How are you? I am going to be web developer in future. I downloaded VSCode. But I do not know how to start it. I need to start index.html and style.css I would be grateful If you could help me in this case.
@christislight
@christislight 27 күн бұрын
Python flask will help! Render index.html static js and static css
@sinaorojlo5980
@sinaorojlo5980 Ай бұрын
I use Vscode what is the theme name?
@DrDeuteron
@DrDeuteron 2 ай бұрын
on post init: beware doing work in the constructor....
@CodeWithArpit-Offical
@CodeWithArpit-Offical 3 ай бұрын
good
@bibekbhusansahoo9412
@bibekbhusansahoo9412 2 ай бұрын
It's same as record class in java
@johnschmitt9158
@johnschmitt9158 2 ай бұрын
Well done. I wish instructors would at least mention that types are not necessary to write dataclasses. No field needs a type associated with it. Types are nothing but comments in Python, unless tools beyond bare python are invoked.
@carl2488
@carl2488 2 ай бұрын
So you can just create fields like: class Point() x y Can you?
@Muhaiminul_coding_club
@Muhaiminul_coding_club 3 ай бұрын
i like this
@RishantKarn-ws3ce
@RishantKarn-ws3ce 3 ай бұрын
Can you tell something about devin please? is coders's job dead?
@Chill018
@Chill018 21 күн бұрын
great video as always but.. am I the only one who heard him say "Codder" for color? :'D
@bechirzouaoui5821
@bechirzouaoui5821 3 ай бұрын
I love the ide you are using can you share it with us ?
@TechWithTim
@TechWithTim 3 ай бұрын
It’s VSCode
@rohanparasa8606
@rohanparasa8606 3 ай бұрын
I think this is inspired from kotlin data classes
@ogif2
@ogif2 3 ай бұрын
Sublime?🤔
@edwardmacnab354
@edwardmacnab354 3 ай бұрын
invents python because perl was too weird . Python becomes weirder .
@repairstudio4940
@repairstudio4940 3 ай бұрын
I ❤ it's weirdness. 😊
@GiannakYT
@GiannakYT 3 ай бұрын
"Object-oriented programming an exceptionally bad idea which could only have originated in California"-Dijkstra
@goodlookinouthomie1757
@goodlookinouthomie1757 2 ай бұрын
What's the better option and why? In terms that a beginner like me would understand.
@GiannakYT
@GiannakYT 2 ай бұрын
@@goodlookinouthomie1757 are you asking why it is used?
@goodlookinouthomie1757
@goodlookinouthomie1757 2 ай бұрын
@@GiannakYT Well just generally what is the alternative to OOP. And yes i suppose why you would use that.
@GiannakYT
@GiannakYT 2 ай бұрын
@@goodlookinouthomie1757 Functional programming is an alternative.
@sebastianquiroz7271
@sebastianquiroz7271 11 күн бұрын
​@@goodlookinouthomie1757 in reality it depends on the scope of your programming. Need a quick and simple script that youre not gonna change just write global variables and operations. What you will find quickly enough is that some steps are repeated and you can write those steps as a function. Then you would use a mix of global and functional programming. If you continue scaling your project is that some variables are used in a section and not used any more, so it makes sense to separate those steps in to bigger functions, to save memory, also you would gain more flexibility as you would know which variables are used in each function and changing it once changes it for the whole script. If you continue scaling your project you may find some functions are called many times and each of those times something little changes, so you create a class that calls those functions and may change it. Another option is you want your script to have individual features and features that are a mix of the others, so a class could group those features (functions) as one and you can call them individually or in a group as your new function. So mainly you sacrifice more work to implement functions and or classes but gain flexibility or save lines of code for repetitions. Note this are examples and theres more pros and cons for using each paradigm.
@murphygreen8484
@murphygreen8484 3 ай бұрын
I only ever use dataclasses when making classes
@sweetphilly2
@sweetphilly2 9 күн бұрын
Lombok for Python it seems
@z.8477
@z.8477 2 ай бұрын
please DO NOT USE THESE ANKWARD FACE CHANGES FOR THUMBNAIL LIKE OTHERS! its maybe working but it is stupid...
@TimoYlhainen
@TimoYlhainen 2 ай бұрын
As a programing language, Python is a total failure. And it's success and popularity is a tragedy.
@kazihiseguy-fernand4637
@kazihiseguy-fernand4637 2 ай бұрын
Huh ?
@alexanderelgert6037
@alexanderelgert6037 2 ай бұрын
def __str__(self): return self.__repr__() def __repr__(self): return class__repr(self) ... def class__repr(classo): d_ = classo.__dict__ # class dictionary i = ' ' if d_ else ' ' # indent return f'{classo.__class__.__name__}() >'
@simonmasters3295
@simonmasters3295 Ай бұрын
I liked your code comment, but I don't understand it...
@alexanderelgert6037
@alexanderelgert6037 Ай бұрын
@@simonmasters3295 If you put the first two functions into a class, these ones are called if you want a string representation for the class instance object. The class__repr function is used to list all parameters assigned to this instance. This is very handy, if you want to know what data an instance owns.
@alexanderelgert6037
@alexanderelgert6037 Ай бұрын
@@simonmasters3295 If you look at the code at 0:24, there is a static __repr__ method. If you add another instance property you would have to extend the method. The approach I am using is generic, you can use it on every class and it happily list all the properties recursively.
@alexanderelgert6037
@alexanderelgert6037 Ай бұрын
@@simonmasters3295 trying to answer the third time ...
@alexanderelgert6037
@alexanderelgert6037 Ай бұрын
@@simonmasters3295 Please look at pos 0:24 in the video, the __repr__ function is static, if you extend the class, you have to extend the f-string. My solution is generic, it works for all classes. You can put the class__repr function in your own library, it lists all properties for an object using the classes __dict__ dictionary.
Python Generators Explained
28:37
Tech With Tim
Рет қаралды 144 М.
10 ULTIMATE Python Tips 🔥
16:42
Tech With Tim
Рет қаралды 61 М.
I Built a Shelter House For myself and Сat🐱📦🏠
00:35
TooTool
Рет қаралды 28 МЛН
ПООСТЕРЕГИСЬ🙊🙊🙊
00:39
Chapitosiki
Рет қаралды 61 МЛН
Hot Ball ASMR #asmr #asmrsounds #satisfying #relaxing #satisfyingvideo
00:19
Oddly Satisfying
Рет қаралды 27 МЛН
How Senior Programmers ACTUALLY Write Code
13:37
Thriving Technologist
Рет қаралды 1,3 МЛН
This Is Why Python Data Classes Are Awesome
22:19
ArjanCodes
Рет қаралды 790 М.
Understanding *args And **kwargs In Python || Born2Code
5:11
Born2Code
Рет қаралды 4,5 М.
Python's 5 Worst Features
19:44
Indently
Рет қаралды 84 М.
Pydantic Tutorial • Solving Python's Biggest Problem
11:07
pixegami
Рет қаралды 239 М.
PLEASE Use These 5 Python Decorators
20:12
Tech With Tim
Рет қаралды 94 М.
10 Python Comprehensions You SHOULD Be Using
21:35
Tech With Tim
Рет қаралды 111 М.
5 Tips To Write Better Python Functions
15:59
Indently
Рет қаралды 87 М.
Python 101: Learn the 5 Must-Know Concepts
20:00
Tech With Tim
Рет қаралды 1 МЛН
I Built a Shelter House For myself and Сat🐱📦🏠
00:35
TooTool
Рет қаралды 28 МЛН