Python dataclasses will save you HOURS, also featuring attrs
Vložit
- čas přidán 3. 04. 2021
- Get rid of boilerplate writing classes using dataclasses!
In this video we learn about dataclasses and how to use them, as well as the related attrs library that dataclasses were based on.
Note: As of Python 3.10 dataclasses DO support slots.
― mCoding with James Murphy (mcoding.io)
Source code: github.com/mCodingLLC/VideosS...
attrs library: www.attrs.org/en/stable/examp...
SUPPORT ME ⭐
---------------------------------------------------
Patreon: / mcoding
Paypal: www.paypal.com/donate/?hosted...
Other donations: mcoding.io/donate
BE ACTIVE IN MY COMMUNITY 😄
---------------------------------------------------
Discord: / discord
Github: github.com/mCodingLLC/
Reddit: / mcoding
Facebook: / james.mcoding - Věda a technologie
A "Production Python Code" course by you would be a hit. These are the things I never picked up as a mostly self taught programmer. Great stuff.
Thanks!
I also think this would be cool, but would be hard not making it too long while staying informative. It seems like many CZcams channels favor having a 5 hour crash course. Beginners don’t have the attention span (imo) because they’ll have so many questions.
@@logankillen2669 this isn't beginner content, it's intermediate content for programmers who want to improve.
@@johnr3936 which are the hardest tutorials to find!
This would be actually what I need ! Focus on real world professional prduction-code. Either to be better qualified for a job or to particiapate in big projects like pandas, numpy etc.
I love that you show WHY you would want to use this rather than just what it is. It really drives home the actual usefulness of this
I think that's what's really the important part.
Totally agree! Happy CZcams recommend me your channel!
Thanks! The WHY is the part that is missing almost everywhere else. Subscribed and hoping for more :-)
Agree 100%
Agreed! Context matters.
Update: as of python 3.10, slots are now supported in in-built dataclasses with the ``slots`` argument
what is that?
I have been looking for such tutorials (unique less known concepts for intermediate programmers) for years now. This channel is an absolute gem!
Great work James!
Thanks so much for your kind words!
Thank you for this valuable video! Before watching your video, I assumed dataclasses were just a Python version of C structs, for cases where you didn't want to add functions in a class but didn't want a raw tuple either. After watching your video, I learned that dataclasses are much more sophisticated than that.
Glad it was helpful!
I love the way you start by explaining and go to the solutions. Most people just start by showing what it does and how to do it, without ever mentioning why we really need it. Keep going, your style of teaching will reach millions of people.
Yes
Best Python videos on youtube. Or maybe most valuable? Covering so many useful and unique topics no one else seems to.
Wow, thanks!
@@mCoding thank you very much for your videos. I know something new every video.
I don't think my jaw has ever dropped from a coding video before. The beauty of being an engineer is you learn something new every day. So much hidden utility in python its amazing!
I'll remember this. I don't know much about OOP so I didn't understand much. When I'll learn, I'll re-watch this video.
You don't need to know about OOP to understand classes! You are simply making your own class that holds an int and a str!
@@mCoding Classes are the very basics of OOP. If you don't know about OOP, chances are you don't know how classes work either.
You definitely need classes for OOP, but classes can be used for other programming paradigms besides OOP, though I guess you are right in that usually classes are introduced in the context of OOP.
@@mCoding Yeah, I have seen classes used in programs, where no OOP was involved. In those programs, classes were used just to pack data into one structure. However, I've not seen @property, __hash__, or how to make them immutable so I thought they were covered in OOP.
I strongly recommend that you learn Python and OOP immediately.
Cool functionality. Thanks for sharing
@ 3:32 the dead pan to the camera... Lol !
Love the dry humor
I will slowly dial up the humor moving forward.
@@mCoding its absolutely perfect the way it is!
3:30
Your vids are the perfect thing for me, I usually get lost in long videos. Yours are short, simple and actually demonstrate applications of it
Great to hear!
Wow, this is an outstanding video! Thank you so much. I just found out you’ve got a Python course, I’m in
Nice
Seen a few Python dataclasses videos but this one is the clearest and most informative in a short time. Well done!
Well explained without sounding fancy. It's one of the reasons I like your videos: you know how to get to the point.
This is the type of stuff classes should teach. I really appreciate your content.
This is actually one of the best CS-related channels I've watched
But its not c sharp, its python
@@aa-nw8hk CS = computer science
I have just started experimenting with Python to use animation libraries from Grant Sanderson / 3Blue1Brown and have seen your videos pop up. Your organization and presentation of these tips is great for both initial learning and reference. Very concise, straightforward examples without cryptic foo / bar based variables, etc. New subscriber!
Best video on dataclasses I have ever seen by far. Loved the approach of firstly doiny an example implementation, then showing the issues found, and finally solving them using the feature displayed.
Awesome, thank you!
I am watching all your videos since a random youtube recommendation. Some of the best coding videos I have seen yet, very clear, easy to follow and often about topics and features I would never thought that I will benefit from. Thanks!
Great to hear!
As someone who has been slowly getting into the nitty gritty of writing classes, this video was informative, scary, and then relieving. Not only have you showed me what I have yet to learn, but also why it's something that should understood, but hopefully never written.
Thanks for shining a spotlight on these very useful Python modules with a good, concise tutorial. Great comparison between attrs and dataclasses, too.
I'm starting to realize how damn useful class and method decorators are. I have the cumbersome Learning Python book by Orielly but these videos offer a lot of value due to how terse they are. @cache and @dataclass all day baby
Books actually contain a lot of useful stuff! Lucky for me I love reading terse literature (high signal-to-noise-ratio).
@@mCoding Do you have some book recommendations?
@@maltml the human brain tend to work in a way - that if you didn't use it, you will forgot it....thus reading the book without goal is just a waste of time. Better to lvl the skill in ability to search for information you actually needed and when you need it.
It's like - i'm watching this vid; yep cool stuff, standard lib. But if you would have a hundreds of classes, transforming each via class decorator would eat performance on module load.
don't diss lutz ;p
These are really great videos! I'm just learning Python for work and they're extremely helpful with simple and clear explanations.
About 2 years ago I came over from writing bare C to having Python as my daily driver. I've grown to really enjoy the language. 95% of the time it suits my needs and videos like this just illustrate how absolutely brilliant it can be. Thanks for the new trick up my sleeve!!!
Your videos have a high learning value and I, as well as many others, appreciate your effort in making coding content. Although most of the times I do not understand what you're talking about, obviously due to me being a beginner in programming (Python), I will make sure to keep some of the things in mind and come back here much later when I'm ready.
Subbed to this channel at like 300 subs and now 2 weeks later you're at 12.3k. you're going places my dude, keep it up, great content
Appreciate it!
Dataclasses are a beautiful idea, and hearing "There's gotta be a better way!" reminds me of Sir Raymond's classes. Great stuff 👍!
Thanks for putting the time and effort to explain dataclasses thoroughly. You're the best!!
**Note: As of Python 3.10 data classes DO support slots.**
Thanks for adding it to the description, this video is gold!
Of course! Thanks for watching!
@@mCoding It's been 3 hours and I am still watching your videos! I was just watching another video!
👏😮 that means a lot, thanks! Glad you enjoy my videos so much!
U got me with the “I just subscribed “ look lolol
This is great! You do a great job of explaining these features. I always found classes to be annoying to deal with in Python and have stayed away from OOP because of that, but this approach might change my mind.
What makes this video really useful is thay you show why you need it rather than what does it do.
Your videos are extremely information rich, yet not "dense" in terms of accessibility of the ideas.
Amazing video, love it! (loved the "hinting eye contact" @ 3:30 ;)
C# dev here learning python for my Software Engineering thesis. I love your videos, directly to the point and with a lot of useful information!
Great stuff man! Im new to the channel but I've already learnt a lot from your videos! Keep churning out these high quality content!! :D
Thanks! Will do!
LMAO That pause and eye contact after he read "I just subscribed". I FELT THE PRESSURE MAN!
:D subliminal messaging
This video gave me goosebumps...
This feat is amazing!!!
Great video! Very succint and useful!
Thank you so much!
Subscribed. Really great one. Will be following more of yours tutorials.
that little pause at 3:30 made me subscribe 😂
This is the first video I've watched on this channel. I love this guy! Great work!
Wow, thanks!
Higher than my current level, but when I get there, this will be even fantastic. THANK YOU !!!! :D
Insanely clear and valuable tutorials dude! Subbed in a millisecond
Hey, thanks!
Good intermediate YT content is hard to come by, subbed! Amazing post 😁
Very well explained. Thank you!
Great video, I just found your channel and it's great, congrats
3:31 the pause and cold look after "I just subscribed" :D
😇
One of the best Python OOP videos I've ever seen. Thanks!!
Glad it was helpful!
I've just used these for my users in flask. Great explanation
This is really cool and I just learned that you can put decorators on classes :) thank you!! You have earned yourself a subscriber.
Thanks for subbing!
Really liked this. I'm building a library for Kivy-based apps that provides an interface for working with TastyPie on a Django-based server, and this is exactly what I need for storing information related to each model schema exposed through the API. So much simpler and readable. Always good to learn more about Python, thanks for the vid!
You never fail to amuse me.
Didn't know that fields thing
Thx!
What a nice and clear explanation! I will try to implement this in my thesis project!
Go for it!
Wow, I commented and asked for a dataclass vid a week ago and you actually delivered. Nice :)
Hope you enjoyed it!
That was soo awesome .. I saved a lot of time writing code for json responses ! Really awesome stuff 😁
Very cool. I can see this saving alot of time. Python never ceases to surprise me
I know it saves me a lot of time!
I love that you called out the issue with __slots__
The default dict instance representation has turned my implentation into a massive memory hog, tuple instance representation fixed that!
Maybe __slots__ and other memory optimization and profiling techniques could be the topic of a future video!
I'll cover slots eventually, but that's a more technical topic!
I think NamedTuple from typing module used slots by default. Also seem to work with @property.
I use slots to avoid typos. Particularly important if your class has writable properties.
as for now, slots are available in dataclasses too (since python 3.10)
wow bro this is amazing. Thanks for doing what you do man!
Wonderful video! Thanks a lot for this.
This is how a tutorial should be! Loved it 💕
When I first came across decorators and understood that the dectaror takes the function or class as an argument, I thought this will have so many uses. Data classes are gold
This is the perfect intermediate to advanced python concepts I would like to see covered in a single comprehensive course. Your explanations are very punctual and I seem to really get a lot out of your videos. I am glad I found this channel. You should really consider, as others have suggested, to make such a course.
Noted!
Apart from the amazing video, you're acting skills are on point :D
Wow. After this video I think I really got the gist of Python dataclasses. And so many ideas popped up in my head to refactor some code. Thanks a lot! 😃
Great vid! Keep up the good work!
I love you, perfect video. Saved me a lot of time.
I've being doing python for a while now and a lot of things here are new to me. Thanks for making this
Glad it was helpful!
I am way too noob for this video but I'll watch it whole and watch it again after 6 months. Thanks!
Excellent and to the point. Subscribed.
You have a very deep insight into the python source code
3m30... That is the new Deathstare!! Awesome, Subbed. Great vid and Mitch appreciated.
HOLY SHIT. Why didn't I just learn this ages ago? It's fantastic!
Love this. Real-world implementations and uses
Thanks!
This is excellent. Subscribed.
another banger, great work mcoding, you're the best
I appreciate that!
The new mic has arrived!
Indeed it has! Let me know if the audio quality sounds good or if I've messed something up!
@@mCoding its perfect :)
It sounds much better. Though it sounds like there's a little bit of reverb somehow
@@mCoding Your voice sounds perfect, but you can hear some vibrations from keyboard sounds in the audio
I actually left typing noises in on purpose because they sound satisfying... not sure if others agree or would rather not hear me clicking and clacking.
WHAAAAAA
THIS HELPS SOOO MUCH WITH MY AST NODES
THANK YOU SO MUCH
You are very welcome 😊
That 3:29 was hillariously sneaky! Good video btw
That's a fantastic feature! Thanks for making this great video
And thank you for watching!
I'm hooked to this course bro, a huge thanks for this.
No problem 👍
This was so detailed - great stuff !
Glad you liked it!
This is a very useful concept. Another great video!
Thanks again!
as a beginner with some basic knowledge it is the content I started peeking in, some professional stuff that I can learn actually makes life much easier!
Glad to peel back the curtain for you!
Such high quality content thanks for this, you deserve more subs
I appreciate that so much!
Most valuable 9 minutes of my python career
Thanks for the kind words!
Thank you so much, I used this in one of my projects and it is really useful :)
Great to hear!
Awesome vids. Indeed implementing this saving a lot of my time
Glad it helped!
Thank you for another excellent video.
Thanks for watching!
a perfect explanation, thank you
Great video! Rare material in CZcams. Thank you!
Glad you enjoyed it!
Thank You!!! Keep sharing …please. If you can and have the time, of course. 😎👏🏼👏🏼👏🏼😎
You bet!
I especially liked it - subscribed! thanks for the tips
Awesome, thank you!
You make it even more complex
This channel is a goldmine.
Many thanks! I appreciate your kind words.
That was a great video. Thank you❤️
This was an amazing video!
Nicely structured video.
Thanks!
*You* my friend are the new Cory Schafer! Thank you for contributing to free education :D
You're ON ANOTHER LEVEL ❤️
This video is awesome thank you for teaching this.
You're very welcome!