Тёмный

Python dataclasses will save you HOURS, also featuring attrs 

mCoding
Подписаться 227 тыс.
Просмотров 870 тыс.
0% 0

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

Наука

Опубликовано:

 

3 апр 2021

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 851   
@patrickjdarrow
@patrickjdarrow 3 года назад
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
@mCoding 3 года назад
Thanks!
@logankillen2669
@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 RU-vid channels favor having a 5 hour crash course. Beginners don’t have the attention span (imo) because they’ll have so many questions.
@johnr3936
@johnr3936 3 года назад
@@logankillen2669 this isn't beginner content, it's intermediate content for programmers who want to improve.
@johnnybarrett3445
@johnnybarrett3445 3 года назад
@@johnr3936 which are the hardest tutorials to find!
@flowers134
@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.
@eoghainlebioda1396
@eoghainlebioda1396 3 года назад
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
@mCoding 3 года назад
I think that's what's really the important part.
@AlexGb007
@AlexGb007 3 года назад
Totally agree! Happy RU-vid recommend me your channel!
@parryhotter18
@parryhotter18 Год назад
Thanks! The WHY is the part that is missing almost everywhere else. Subscribed and hoping for more :-)
@jeffreyhunter4115
@jeffreyhunter4115 Год назад
Agree 100%
@QuintinMassey
@QuintinMassey 7 месяцев назад
Agreed! Context matters.
@octopirate-bak
@octopirate-bak 2 года назад
Update: as of python 3.10, slots are now supported in in-built dataclasses with the ``slots`` argument
@msatul1305
@msatul1305 5 месяцев назад
what is that?
@dhanushkari9042
@dhanushkari9042 2 года назад
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
@mCoding 2 года назад
Thanks so much for your kind words!
@zishiwu7757
@zishiwu7757 3 года назад
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
@mCoding 3 года назад
Glad it was helpful!
@vnpikachu4627
@vnpikachu4627 3 года назад
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
@samueljehanno Год назад
Yes
@nicke20686
@nicke20686 3 года назад
Best Python videos on youtube. Or maybe most valuable? Covering so many useful and unique topics no one else seems to.
@mCoding
@mCoding 3 года назад
Wow, thanks!
@gagik1
@gagik1 3 года назад
@@mCoding thank you very much for your videos. I know something new every video.
@DSCuber
@DSCuber 2 года назад
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!
@usharma1624
@usharma1624 3 года назад
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
@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
@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
@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
@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
@TheHippyHoppyHippo 3 года назад
I strongly recommend that you learn Python and OOP immediately.
@grahamjoss4643
@grahamjoss4643 3 года назад
Cool functionality. Thanks for sharing @ <a href="#" class="seekto" data-time="212">3:32</a> the dead pan to the camera... Lol ! Love the dry humor
@mCoding
@mCoding 3 года назад
I will slowly dial up the humor moving forward.
@mustafamotiwala2335
@mustafamotiwala2335 3 года назад
@@mCoding its absolutely perfect the way it is!
@toxic_narcissist
@toxic_narcissist 3 года назад
3:30
@ethanperry8
@ethanperry8 3 года назад
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
@mCoding 3 года назад
Great to hear!
@mrdbourke
@mrdbourke 3 года назад
Wow, this is an outstanding video! Thank you so much. I just found out you’ve got a Python course, I’m in
@samueljehanno
@samueljehanno Год назад
Nice
@richardchin1545
@richardchin1545 Год назад
Seen a few Python dataclasses videos but this one is the clearest and most informative in a short time. Well done!
@drooten
@drooten 3 года назад
Well explained without sounding fancy. It's one of the reasons I like your videos: you know how to get to the point.
@d8-remy
@d8-remy 3 года назад
This is the type of stuff classes should teach. I really appreciate your content.
@addvert_br0009
@addvert_br0009 3 года назад
This is actually one of the best CS-related channels I've watched
@aa-nw8hk
@aa-nw8hk 3 года назад
But its not c sharp, its python
@addvert_br0009
@addvert_br0009 3 года назад
@@aa-nw8hk CS = computer science
@stratfanstl
@stratfanstl 2 года назад
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!
@carlesg0n
@carlesg0n 3 года назад
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
@mCoding 3 года назад
Awesome, thank you!
@schneeekind
@schneeekind 3 года назад
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
@mCoding 3 года назад
Great to hear!
@xavierdingeldein9336
@xavierdingeldein9336 3 года назад
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.
@mmartel
@mmartel 3 года назад
Thanks for shining a spotlight on these very useful Python modules with a good, concise tutorial. Great comparison between attrs and dataclasses, too.
@kylefluto5384
@kylefluto5384 3 года назад
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
@mCoding 3 года назад
Books actually contain a lot of useful stuff! Lucky for me I love reading terse literature (high signal-to-noise-ratio).
@maltml
@maltml 3 года назад
​@@mCoding Do you have some book recommendations?
@s.i.m.c.a
@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
@narnbrez 2 года назад
don't diss lutz ;p
@ropro9817
@ropro9817 2 года назад
These are really great videos! I'm just learning Python for work and they're extremely helpful with simple and clear explanations.
@taylormallory8705
@taylormallory8705 2 года назад
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!!!
@jorgemfgoncalves
@jorgemfgoncalves 2 года назад
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.
@williambos4410
@williambos4410 3 года назад
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
@mCoding 3 года назад
Appreciate it!
@anirangoncalvesbr
@anirangoncalvesbr 3 года назад
Dataclasses are a beautiful idea, and hearing "There's gotta be a better way!" reminds me of Sir Raymond's classes. Great stuff 👍!
@HubertRozmarynowski
@HubertRozmarynowski Год назад
Thanks for putting the time and effort to explain dataclasses thoroughly. You're the best!!
@lordtejas9659
@lordtejas9659 3 года назад
**Note: As of Python 3.10 data classes DO support slots.** Thanks for adding it to the description, this video is gold!
@mCoding
@mCoding 3 года назад
Of course! Thanks for watching!
@lordtejas9659
@lordtejas9659 3 года назад
@@mCoding It's been 3 hours and I am still watching your videos! I was just watching another video!
@mCoding
@mCoding 3 года назад
👏😮 that means a lot, thanks! Glad you enjoy my videos so much!
@2fritazz
@2fritazz 3 года назад
U got me with the “I just subscribed “ look lolol
@kelkka7
@kelkka7 3 года назад
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.
@bettercalldelta
@bettercalldelta 3 года назад
What makes this video really useful is thay you show why you need it rather than what does it do.
@ChasmChaos
@ChasmChaos 3 года назад
Your videos are extremely information rich, yet not "dense" in terms of accessibility of the ideas.
@ciberman
@ciberman Год назад
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!
@cawinchan4282
@cawinchan4282 3 года назад
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
@mCoding 3 года назад
Thanks! Will do!
@bartugonulalan
@bartugonulalan 2 года назад
LMAO That pause and eye contact after he read "I just subscribed". I FELT THE PRESSURE MAN!
@mCoding
@mCoding 2 года назад
:D subliminal messaging
@thiamath
@thiamath 3 года назад
This video gave me goosebumps... This feat is amazing!!! Great video! Very succint and useful!
@mCoding
@mCoding 3 года назад
Thank you so much!
@travel.tales.official
@travel.tales.official Месяц назад
Subscribed. Really great one. Will be following more of yours tutorials.
@tiiibo
@tiiibo 2 года назад
that little pause at <a href="#" class="seekto" data-time="210">3:30</a> made me subscribe 😂
@mujeebishaque
@mujeebishaque 2 года назад
This is the first video I've watched on this channel. I love this guy! Great work!
@mCoding
@mCoding 2 года назад
Wow, thanks!
@kychemclass5850
@kychemclass5850 2 года назад
Higher than my current level, but when I get there, this will be even fantastic. THANK YOU !!!! :D
@johnnybarrett3445
@johnnybarrett3445 3 года назад
Insanely clear and valuable tutorials dude! Subbed in a millisecond
@mCoding
@mCoding 3 года назад
Hey, thanks!
@WhyNotProgram
@WhyNotProgram Год назад
Good intermediate YT content is hard to come by, subbed! Amazing post 😁
@jeffreyhunter4115
@jeffreyhunter4115 Год назад
Very well explained. Thank you!
@fahimulislam7331
@fahimulislam7331 2 года назад
<a href="#" class="seekto" data-time="211">3:31</a> the pause and cold look after "I just subscribed" :D
@mCoding
@mCoding 2 года назад
😇
@ksz7241
@ksz7241 2 года назад
Great video, I just found your channel and it's great, congrats
@rafael.beirigo
@rafael.beirigo Год назад
Amazing video, love it! (loved the "hinting eye contact" @ <a href="#" class="seekto" data-time="210">3:30</a> ;)
@thatguy6664
@thatguy6664 3 года назад
One of the best Python OOP videos I've ever seen. Thanks!!
@mCoding
@mCoding 3 года назад
Glad it was helpful!
@seasong7655
@seasong7655 7 месяцев назад
I've just used these for my users in flask. Great explanation
@richardme123
@richardme123 3 года назад
This is really cool and I just learned that you can put decorators on classes :) thank you!! You have earned yourself a subscriber.
@mCoding
@mCoding 3 года назад
Thanks for subbing!
@2Sor2Fig
@2Sor2Fig 3 года назад
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!
@JohnZakaria
@JohnZakaria 3 года назад
You never fail to amuse me. Didn't know that fields thing
@mCoding
@mCoding 3 года назад
Thx!
@kasta867
@kasta867 3 года назад
What a nice and clear explanation! I will try to implement this in my thesis project!
@mCoding
@mCoding 3 года назад
Go for it!
@dgnikon
@dgnikon 3 года назад
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
@mCoding 3 года назад
I'll cover slots eventually, but that's a more technical topic!
@Avicenna697
@Avicenna697 3 года назад
I think NamedTuple from typing module used slots by default. Also seem to work with @property.
@lawrencedoliveiro9104
@lawrencedoliveiro9104 3 года назад
I use slots to avoid typos. Particularly important if your class has writable properties.
@omgwtfafterparty
@omgwtfafterparty Год назад
as for now, slots are available in dataclasses too (since python 3.10)
@sanmeetsingh4538
@sanmeetsingh4538 2 года назад
That was soo awesome .. I saved a lot of time writing code for json responses ! Really awesome stuff 😁
@raymondzhao5644
@raymondzhao5644 3 года назад
Wow, I commented and asked for a dataclass vid a week ago and you actually delivered. Nice :)
@mCoding
@mCoding 3 года назад
Hope you enjoyed it!
@aidanfarhi367
@aidanfarhi367 3 года назад
Very cool. I can see this saving alot of time. Python never ceases to surprise me
@mCoding
@mCoding 3 года назад
I know it saves me a lot of time!
@fartzy
@fartzy 2 года назад
wow bro this is amazing. Thanks for doing what you do man!
@vighneshpp
@vighneshpp Год назад
Wonderful video! Thanks a lot for this.
@constantfear
@constantfear 2 года назад
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
@amazed4778
@amazed4778 Год назад
This is how a tutorial should be! Loved it 💕
@paologhezzo4276
@paologhezzo4276 3 года назад
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
@mCoding 3 года назад
Noted!
@datenschauer
@datenschauer Год назад
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! 😃
@anonyme103
@anonyme103 2 года назад
Apart from the amazing video, you're acting skills are on point :D
@fredericoamigo
@fredericoamigo 2 года назад
Great vid! Keep up the good work!
@ShadartS
@ShadartS 2 года назад
I love you, perfect video. Saved me a lot of time.
@Khushpich
@Khushpich 3 года назад
I've being doing python for a while now and a lot of things here are new to me. Thanks for making this
@mCoding
@mCoding 3 года назад
Glad it was helpful!
@vaishantsah
@vaishantsah 3 месяца назад
I am way too noob for this video but I'll watch it whole and watch it again after 6 months. Thanks!
@FarazMazhar
@FarazMazhar 3 года назад
Excellent and to the point. Subscribed.
@roniabraham9602
@roniabraham9602 2 года назад
You have a very deep insight into the python source code
@cosmicpuma1409
@cosmicpuma1409 3 года назад
3m30... That is the new Deathstare!! Awesome, Subbed. Great vid and Mitch appreciated.
@DarkWizard316
@DarkWizard316 Год назад
HOLY SHIT. Why didn't I just learn this ages ago? It's fantastic!
@poke_champ
@poke_champ 3 года назад
Love this. Real-world implementations and uses
@mCoding
@mCoding 3 года назад
Thanks!
@daniellapm8808
@daniellapm8808 3 года назад
This is excellent. Subscribed.
@aqworldsmaster88
@aqworldsmaster88 3 года назад
another banger, great work mcoding, you're the best
@mCoding
@mCoding 3 года назад
I appreciate that!
@AnyFactor
@AnyFactor 3 года назад
The new mic has arrived!
@mCoding
@mCoding 3 года назад
Indeed it has! Let me know if the audio quality sounds good or if I've messed something up!
@Wiedzmin940
@Wiedzmin940 3 года назад
@@mCoding its perfect :)
@deViant14
@deViant14 3 года назад
It sounds much better. Though it sounds like there's a little bit of reverb somehow
@toktik7576
@toktik7576 3 года назад
@@mCoding Your voice sounds perfect, but you can hear some vibrations from keyboard sounds in the audio
@mCoding
@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.
@otesunki
@otesunki 2 года назад
WHAAAAAA THIS HELPS SOOO MUCH WITH MY AST NODES THANK YOU SO MUCH
@mCoding
@mCoding 2 года назад
You are very welcome 😊
@dominikprager5338
@dominikprager5338 2 года назад
That <a href="#" class="seekto" data-time="209">3:29</a> was hillariously sneaky! Good video btw
@dexternepo
@dexternepo 3 года назад
That's a fantastic feature! Thanks for making this great video
@mCoding
@mCoding 3 года назад
And thank you for watching!
@samtoya
@samtoya 3 года назад
I'm hooked to this course bro, a huge thanks for this.
@mCoding
@mCoding 3 года назад
No problem 👍
@Jaun_
@Jaun_ 3 года назад
This was so detailed - great stuff !
@mCoding
@mCoding 3 года назад
Glad you liked it!
@vasilnikolov8576
@vasilnikolov8576 3 года назад
This is a very useful concept. Another great video!
@mCoding
@mCoding 3 года назад
Thanks again!
@therzook
@therzook 3 года назад
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
@mCoding 3 года назад
Glad to peel back the curtain for you!
@itzblinkzy1728
@itzblinkzy1728 3 года назад
Such high quality content thanks for this, you deserve more subs
@mCoding
@mCoding 3 года назад
I appreciate that so much!
@stevecarter8810
@stevecarter8810 3 года назад
Most valuable 9 minutes of my python career
@mCoding
@mCoding 3 года назад
Thanks for the kind words!
@Moody0101
@Moody0101 3 года назад
Thank you so much, I used this in one of my projects and it is really useful :)
@mCoding
@mCoding 3 года назад
Great to hear!
@inxiousinx7993
@inxiousinx7993 3 года назад
Awesome vids. Indeed implementing this saving a lot of my time
@mCoding
@mCoding 3 года назад
Glad it helped!
@tassoskat8623
@tassoskat8623 3 года назад
Great video! Rare material in RU-vid. Thank you!
@mCoding
@mCoding 3 года назад
Glad you enjoyed it!
@technowey
@technowey 3 года назад
Thank you for another excellent video.
@mCoding
@mCoding 3 года назад
Thanks for watching!
@seaniam
@seaniam 3 года назад
I especially liked it - subscribed! thanks for the tips
@mCoding
@mCoding 3 года назад
Awesome, thank you!
@diegowh
@diegowh 7 месяцев назад
a perfect explanation, thank you
@geekchiq5431
@geekchiq5431 3 года назад
Thank You!!! Keep sharing …please. If you can and have the time, of course. 😎👏🏼👏🏼👏🏼😎
@mCoding
@mCoding 3 года назад
You bet!
@pythonista5548
@pythonista5548 7 месяцев назад
You make it even more complex
@DrDemolition
@DrDemolition 2 года назад
This channel is a goldmine.
@mCoding
@mCoding 2 года назад
Many thanks! I appreciate your kind words.
@behnamsalehi9765
@behnamsalehi9765 3 года назад
That was a great video. Thank you❤️
@anupamdash1102
@anupamdash1102 2 года назад
*You* my friend are the new Cory Schafer! Thank you for contributing to free education :D
@simaphore
@simaphore Год назад
This was an amazing video!
@user-vx6zk5jj4e
@user-vx6zk5jj4e 3 года назад
Nicely structured video.
@mCoding
@mCoding 3 года назад
Thanks!
@subhodeepsarkar7611
@subhodeepsarkar7611 3 года назад
You're ON ANOTHER LEVEL ❤️
@hx9d674
@hx9d674 3 года назад
This video is awesome thank you for teaching this.
@mCoding
@mCoding 3 года назад
You're very welcome!
Далее
25 nooby Python habits you need to ditch
9:12
Просмотров 1,7 млн
How To Use: "@dataclass" In Python (Tutorial 2023)
15:01
А что если не умеешь играть?🥲
00:46
СКАЧАЛ РОДИТЕЛЯМ МУЗЫКУ 8
00:47
Просмотров 178 тыс.
This Is Why Python Data Classes Are Awesome
22:19
Просмотров 791 тыс.
super/MRO, Python's most misunderstood feature.
21:07
Просмотров 212 тыс.
All 71 built-in Python functions
19:58
Просмотров 40 тыс.
Python Decorators in 15 Minutes
15:14
Просмотров 424 тыс.
Pydantic Tutorial • Solving Python's Biggest Problem
11:07
So You Think You Know Git - FOSDEM 2024
47:00
Просмотров 985 тыс.
Unlocking your CPU cores in Python (multiprocessing)
12:16
Девушка и AirPods Max 😳
0:59
Просмотров 15 тыс.