Python dataclasses will save you HOURS, also featuring attrs
Ғылым және технология
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
Пікірлер: 849
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.
@mCoding
3 жыл бұрын
Thanks!
@logankillen2669
3 жыл бұрын
I also think this would be cool, but would be hard not making it too long while staying informative. It seems like many KZread channels favor having a 5 hour crash course. Beginners don’t have the attention span (imo) because they’ll have so many questions.
@johnr3936
3 жыл бұрын
@@logankillen2669 this isn't beginner content, it's intermediate content for programmers who want to improve.
@johnnybarrett3445
3 жыл бұрын
@@johnr3936 which are the hardest tutorials to find!
@flowers134
3 жыл бұрын
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
@mCoding
3 жыл бұрын
I think that's what's really the important part.
@alilee4505
3 жыл бұрын
Totally agree! Happy KZread recommend me your channel!
@parryhotter18
Жыл бұрын
Thanks! The WHY is the part that is missing almost everywhere else. Subscribed and hoping for more :-)
@jeffreyhunter4115
Жыл бұрын
Agree 100%
@QuintinMassey
7 ай бұрын
Agreed! Context matters.
Update: as of python 3.10, slots are now supported in in-built dataclasses with the ``slots`` argument
@msatul1305
4 ай бұрын
what is that?
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.
@mCoding
3 жыл бұрын
Glad it was helpful!
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!
@mCoding
2 жыл бұрын
Thanks so much for your kind words!
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.
@samueljehanno
Жыл бұрын
Yes
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!
Best Python videos on youtube. Or maybe most valuable? Covering so many useful and unique topics no one else seems to.
@mCoding
3 жыл бұрын
Wow, thanks!
@gagik1
3 жыл бұрын
@@mCoding thank you very much for your videos. I know something new every video.
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.
@mCoding
3 жыл бұрын
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!
@vandelayindustries2971
3 жыл бұрын
@@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.
@mCoding
3 жыл бұрын
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.
@usharma1624
3 жыл бұрын
@@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.
@TheHippyHoppyHippo
3 жыл бұрын
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
@mCoding
3 жыл бұрын
I will slowly dial up the humor moving forward.
@mustafamotiwala2335
3 жыл бұрын
@@mCoding its absolutely perfect the way it is!
@toxic_narcissist
3 жыл бұрын
3:30
Seen a few Python dataclasses videos but this one is the clearest and most informative in a short time. Well done!
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!
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!
@mCoding
3 жыл бұрын
Great to hear!
Well explained without sounding fancy. It's one of the reasons I like your videos: you know how to get to the point.
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.
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
@mCoding
2 жыл бұрын
Great to hear!
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.
@mCoding
3 жыл бұрын
Awesome, thank you!
Thanks for shining a spotlight on these very useful Python modules with a good, concise tutorial. Great comparison between attrs and dataclasses, too.
These are really great videos! I'm just learning Python for work and they're extremely helpful with simple and clear explanations.
This is the type of stuff classes should teach. I really appreciate your content.
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.
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!!!
This is actually one of the best CS-related channels I've watched
@aa-nw8hk
3 жыл бұрын
But its not c sharp, its python
@addvert_br0009
3 жыл бұрын
@@aa-nw8hk CS = computer science
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
@mCoding
3 жыл бұрын
Appreciate it!
**Note: As of Python 3.10 data classes DO support slots.** Thanks for adding it to the description, this video is gold!
@mCoding
3 жыл бұрын
Of course! Thanks for watching!
@lordtejas9659
3 жыл бұрын
@@mCoding It's been 3 hours and I am still watching your videos! I was just watching another video!
@mCoding
3 жыл бұрын
👏😮 that means a lot, thanks! Glad you enjoy my videos so much!
Thanks for putting the time and effort to explain dataclasses thoroughly. You're the best!!
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.
Your videos are extremely information rich, yet not "dense" in terms of accessibility of the ideas.
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
@mCoding
3 жыл бұрын
Books actually contain a lot of useful stuff! Lucky for me I love reading terse literature (high signal-to-noise-ratio).
@maltml
3 жыл бұрын
@@mCoding Do you have some book recommendations?
@s.i.m.c.a
3 жыл бұрын
@@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.
@narnbrez
2 жыл бұрын
don't diss lutz ;p
Dataclasses are a beautiful idea, and hearing "There's gotta be a better way!" reminds me of Sir Raymond's classes. Great stuff 👍!
What makes this video really useful is thay you show why you need it rather than what does it do.
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!
This is the first video I've watched on this channel. I love this guy! Great work!
@mCoding
2 жыл бұрын
Wow, thanks!
Amazing video, love it! (loved the "hinting eye contact" @ 3:30 ;)
Subscribed. Really great one. Will be following more of yours tutorials.
Insanely clear and valuable tutorials dude! Subbed in a millisecond
@mCoding
3 жыл бұрын
Hey, thanks!
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
@mCoding
3 жыл бұрын
Thanks! Will do!
Wow, this is an outstanding video! Thank you so much. I just found out you’ve got a Python course, I’m in
@samueljehanno
Жыл бұрын
Nice
U got me with the “I just subscribed “ look lolol
LMAO That pause and eye contact after he read "I just subscribed". I FELT THE PRESSURE MAN!
@mCoding
2 жыл бұрын
:D subliminal messaging
That was soo awesome .. I saved a lot of time writing code for json responses ! Really awesome stuff 😁
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! 😃
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.
@mCoding
3 жыл бұрын
Noted!
Good intermediate YT content is hard to come by, subbed! Amazing post 😁
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!
Great video, I just found your channel and it's great, congrats
What a nice and clear explanation! I will try to implement this in my thesis project!
@mCoding
3 жыл бұрын
Go for it!
wow bro this is amazing. Thanks for doing what you do man!
This is really cool and I just learned that you can put decorators on classes :) thank you!! You have earned yourself a subscriber.
@mCoding
3 жыл бұрын
Thanks for subbing!
This video gave me goosebumps... This feat is amazing!!! Great video! Very succint and useful!
@mCoding
3 жыл бұрын
Thank you so much!
Wow, I commented and asked for a dataclass vid a week ago and you actually delivered. Nice :)
@mCoding
3 жыл бұрын
Hope you enjoyed 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
One of the best Python OOP videos I've ever seen. Thanks!!
@mCoding
3 жыл бұрын
Glad it was helpful!
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!
@mCoding
3 жыл бұрын
I'll cover slots eventually, but that's a more technical topic!
@Avicenna697
3 жыл бұрын
I think NamedTuple from typing module used slots by default. Also seem to work with @property.
@lawrencedoliveiro9104
3 жыл бұрын
I use slots to avoid typos. Particularly important if your class has writable properties.
@omgwtfafterparty
Жыл бұрын
as for now, slots are available in dataclasses too (since python 3.10)
I've being doing python for a while now and a lot of things here are new to me. Thanks for making this
@mCoding
3 жыл бұрын
Glad it was helpful!
Very well explained. Thank you!
that little pause at 3:30 made me subscribe 😂
I've just used these for my users in flask. Great explanation
This is how a tutorial should be! Loved it 💕
You never fail to amuse me. Didn't know that fields thing
@mCoding
3 жыл бұрын
Thx!
Apart from the amazing video, you're acting skills are on point :D
I am way too noob for this video but I'll watch it whole and watch it again after 6 months. Thanks!
3:31 the pause and cold look after "I just subscribed" :D
@mCoding
2 жыл бұрын
😇
another banger, great work mcoding, you're the best
@mCoding
3 жыл бұрын
I appreciate that!
Such high quality content thanks for this, you deserve more subs
@mCoding
3 жыл бұрын
I appreciate that so much!
I'm hooked to this course bro, a huge thanks for this.
@mCoding
3 жыл бұрын
No problem 👍
The new mic has arrived!
@mCoding
3 жыл бұрын
Indeed it has! Let me know if the audio quality sounds good or if I've messed something up!
@Wiedzmin940
3 жыл бұрын
@@mCoding its perfect :)
@deViant14
3 жыл бұрын
It sounds much better. Though it sounds like there's a little bit of reverb somehow
@toktik7576
3 жыл бұрын
@@mCoding Your voice sounds perfect, but you can hear some vibrations from keyboard sounds in the audio
@mCoding
3 жыл бұрын
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.
Great vid! Keep up the good work!
Higher than my current level, but when I get there, this will be even fantastic. THANK YOU !!!! :D
Very cool. I can see this saving alot of time. Python never ceases to surprise me
@mCoding
3 жыл бұрын
I know it saves me a lot of time!
Wonderful video! Thanks a lot for this.
3m30... That is the new Deathstare!! Awesome, Subbed. Great vid and Mitch appreciated.
This is excellent. Subscribed.
I love you, perfect video. Saved me a lot of time.
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!
@mCoding
3 жыл бұрын
Glad to peel back the curtain for you!
Excellent and to the point. Subscribed.
You have a very deep insight into the python source code
That's a fantastic feature! Thanks for making this great video
@mCoding
3 жыл бұрын
And thank you for watching!
This is a very useful concept. Another great video!
@mCoding
3 жыл бұрын
Thanks again!
This was so detailed - great stuff !
@mCoding
3 жыл бұрын
Glad you liked it!
bro your channel's on fire... keep it up!!!
@mCoding
3 жыл бұрын
Appreciate it! Spread the flame!
Great content. I use pydantic but it’s good to learn the native way for this!
Thank you so much, I used this in one of my projects and it is really useful :)
@mCoding
3 жыл бұрын
Great to hear!
Love this. Real-world implementations and uses
@mCoding
3 жыл бұрын
Thanks!
Never heard of dataclasses. They look super useful! BTW, I really like your channel.
@mCoding
3 жыл бұрын
Awesome, thank you!
I took CS in bachelors, CS in masters and have PhD but never have I crossed this, thanks a lot man, this is actually pretty helpful. it shows how dumb down the CS degrees are right now, No one is doing any code and doing shit that is outdated and have no real life usage.
You're ON ANOTHER LEVEL ❤️
WHAAAAAA THIS HELPS SOOO MUCH WITH MY AST NODES THANK YOU SO MUCH
@mCoding
2 жыл бұрын
You are very welcome 😊
I especially liked it - subscribed! thanks for the tips
@mCoding
3 жыл бұрын
Awesome, thank you!
Awesome vids. Indeed implementing this saving a lot of my time
@mCoding
3 жыл бұрын
Glad it helped!
HOLY SHIT. Why didn't I just learn this ages ago? It's fantastic!
This was an amazing video!
Great presentation! Thanks.
Nicely structured video.
@mCoding
3 жыл бұрын
Thanks!
a perfect explanation, thank you
This is amazing!! Why did I learn about it so late?!?! Thx for the video
@mCoding
3 жыл бұрын
You're welcome!
This is basically like lombok's @Data and @Value for java. Nice stuff!
That was a great video. Thank you❤️
That 3:29 was hillariously sneaky! Good video btw
I'm a beginner, but I started using data classes more ad more just because it was easier to keep things organized and understandable.