Python Decorators in 15 Minutes

Поделиться
HTML-код
  • Опубликовано: 22 ноя 2024

Комментарии • 450

  • @lawrencedoliveiro9104
    @lawrencedoliveiro9104 3 года назад +373

    Just to recap:
    * Every value in Python is an object.
    * Functions and classes are objects.
    * Function definitions and class definitions are best thought of as special kinds of assignment statements, not as declarations; there are no declarations as such in Python.
    Decorators work with classes as well, not just functions. Also worth adding:
    * Every object is an instance of a class.
    Note this also applies to classes, since they are objects.

    • @theobellash6440
      @theobellash6440 3 года назад +6

      Python Fonctions and Classes are C classes... Python is an alphabet soup of C classes and objets and slowly interpreted🍝 spaghetti codes but somehow compréhensive

    • @riosdellacueva6482
      @riosdellacueva6482 3 года назад +2

      use yield

    • @Artaxerxes.
      @Artaxerxes. 3 года назад +1

      It's just a function pointer lmao. You sound really naïve when you call everything an object

    • @arpit743
      @arpit743 2 года назад

      @@Artaxerxes. what's a function pointer

    • @vertigo390
      @vertigo390 2 года назад +2

      Every object is an instance of a class, even classes since they are objects.
      According to this statement, classes are objects, instances of a class which is itself an object, instance of a class which is also itself an object, instance of a class...
      You see where I'm going.
      What's the highest point? There must be a class that isn't an instance of a higher-order class, or it'll repeat infinitely.

  • @willemvdk4886
    @willemvdk4886 3 года назад +264

    I've read about decorators a dozen times. In books, tutorials, documentation of frameworks, etc. This is honestly the first time I actually understand the concept. Best explenation ever. Thanks Tim!

  • @mehregankbi
    @mehregankbi 3 года назад +17

    the best ad for kites. have been seeing the ad everywhere but never wanted it. now i'm liking it

  • @SumanPokhrel0
    @SumanPokhrel0 4 года назад +153

    I looked so many videos, all of them were confusing. But this one just the perfect content I wanted. Thanks for this awesome video

    • @KiteHQ
      @KiteHQ  4 года назад +10

      So glad you found it helpful! Hope you are able to benefit from our other tutorials as well :)

    • @mranonymous7766
      @mranonymous7766 3 года назад +1

      @@KiteHQ Yeah i bought a python course still here watching your videos.

    • @ultimatejy9393
      @ultimatejy9393 3 года назад

      Agree!

    • @nicholasziglio
      @nicholasziglio 3 года назад

      Same here! So well explained.

  • @SovsemNeProstoy
    @SovsemNeProstoy Год назад +1

    When I saw function decorators first time I thoght that it's the easiest theme that I've ever seen, but then I understood how useful and complicated they are. And now, I can say that this tutorial gave me the concept of decorators.

  • @mathiasnagy5976
    @mathiasnagy5976 2 месяца назад

    This is what education used to be like, even the most complex topics, found in the books I own about physics etc. published in the 1950's and before. Start with small chunks of the preliminary concepts. Then put them together slowly, simply and clearly, demonstrating along the way. Then build and finally explain a complex idea. Well done Tim and thank you!

  • @MichielDeSnuyter
    @MichielDeSnuyter 4 года назад +77

    Wow this Kite AI thingy is really advanced, it does a darn good impersonation of that Tim fellow.

    • @ultimatejy9393
      @ultimatejy9393 3 года назад

      So the man voice in this video is generated by AI with impersonating Tim??

  • @ramonsantiago4573
    @ramonsantiago4573 2 года назад

    Tim explains things so well. If he made an advanced python course i would literally "shut up and take my money".

  • @srikanthsukhavasi4860
    @srikanthsukhavasi4860 2 года назад

    I tried to understand Decorators from watching different videos. But trust me I used to be very confused after finishing the video. But, You made me understand Decorators very easily...Thank you.

  • @pawjast
    @pawjast Год назад

    Hands down the best explanation of Python decorators in the whole YT!

  • @Ayoutubeaccount3
    @Ayoutubeaccount3 3 года назад

    this is the first video I watched on the topic and understood it straight away, I think I was lucky as the other comments say they've read lots of documents and watched other videos without understanding it, but seriously dude your explanation and the way you speak makes it easy to follow along

  • @peetk5993
    @peetk5993 2 года назад +1

    I watched this video a year ago, created some decorator functions as snippets that I can use later. Now after a year I needed them so I used the snippets but honestly I forgot how they actually work but saved a link to your video. Watched this again and after 15 mins I understand everythingI need. I really appreciate your work Tim, I honestly think that there is absoutely nothing I could add or remove from your content like they go concisely from zero to a decent level of understanding in really short time.

  • @soyaleye
    @soyaleye 4 года назад +1

    This is by far the most explanatory video for decorators I have seen on RUclips. It does not have the view count to match up to how helpful and insightful this video is.

    • @AmbitiousJay1
      @AmbitiousJay1 4 года назад

      true but have you been able to apply it in a project?

  • @afjalkasim5249
    @afjalkasim5249 2 года назад

    I see so many videos.but not clear how the function works .This is life changing.Krishna bless u sir

  • @kristiantorres1080
    @kristiantorres1080 4 года назад +25

    The best explanation of decorators I've seen so far on youtube!

  • @thomasdr08
    @thomasdr08 Год назад

    Been trying to understand decorators, args, and kwargs for years. No clue how you were able to make this work so quickly and easily but I REALLY appreciate you!

  • @garrenmiller9434
    @garrenmiller9434 2 года назад +17

    Great explanation. I really appreciated that you gave a few concrete examples where decorators are useful instead of cutting off after explaining the functionality.

  • @joekerr5418
    @joekerr5418 4 года назад +86

    hey, it's tech with tim!!

    • @furiousfellow1583
      @furiousfellow1583 4 года назад +9

      my first reaction at reading your comment was like, "duhh yes it is", then I read the channel name and was like WHAT??...

    • @damonchase1922
      @damonchase1922 3 года назад +1

      Kite sponsors his videos

  • @bluefrog-wl2cu
    @bluefrog-wl2cu 9 месяцев назад

    I have seen lots of videos about Decorators. But Honestly It's the only video which helps me to understand the topic

  • @christian37ism
    @christian37ism 3 года назад +3

    Best part of the video. Tim: ‘if you’ve understood this, you’re definitely well on your way to becoming an expert in python.’

    • @daenbermudez3740
      @daenbermudez3740 2 года назад

      That was the worst part for me. I didn't understand

  • @gavintantleff
    @gavintantleff 3 года назад +4

    I love how to the point this video is to the point. No fluff, you just start explaining. Reminds me of Miziziziz tutorials.

    • @samszotkowski
      @samszotkowski 3 года назад +1

      There's literally a minute of intro+ad

    • @MiguelAngel-fw4sk
      @MiguelAngel-fw4sk 3 года назад

      Nope Mizziziziz doesn't put a minute of intro and ad at the beggining of his videos.

    • @gavintantleff
      @gavintantleff 3 года назад

      @@MiguelAngel-fw4sk you're right

  • @mikemace2860
    @mikemace2860 Год назад +2

    Absolutely the best , most concise tutorial on decorators - thank you!

  • @radhika6212
    @radhika6212 7 месяцев назад

    What an explanation, being a technical lead and doing automation in python for years..I would say my fundamentals are stronger now after going through this video..amazing work :)

  • @nonoobott8602
    @nonoobott8602 Год назад

    This is by far the clearest and most intuitive explanation of the concept of decorators I've seen. Thanks for sharing

  • @Adel-pn2up
    @Adel-pn2up 3 месяца назад

    I've had problems with decorators for a long time. This video finally solved it. Thanks ;)

  • @Dtomper
    @Dtomper 3 года назад +12

    That log decorator is so powerful omg. Thank you for this amazing explanation

  • @vikalpnarayan6243
    @vikalpnarayan6243 10 месяцев назад

    Watched many videos on decorators but this is where my search ended.Excellent explanation!

  • @robertschmidt8624
    @robertschmidt8624 Год назад

    I still have some work to do with Decorators, but largely thanks to You I finally think
    I've got it.

  • @elninolol
    @elninolol 8 месяцев назад

    I like the way the video starts with passing function as argument and print function address, very detailed and well explained for a beginner in Python like me. Thank you very much

  • @DelverGames
    @DelverGames Год назад

    this has to be the best explanation to decorators that I have seen. Amazing.

  • @Levendo
    @Levendo Год назад

    I only had to pause at the start and look at your code for a few seconds to figure out where I was messing up. Thanks!

  • @mohammadissa5958
    @mohammadissa5958 4 месяца назад

    thank you so much because after i spend hours of watching tutorials and reading websites i found your video and from the first time i watched your video this consept flew into my mind

  • @edwin5907
    @edwin5907 3 года назад +1

    This is what I wanted to see, someone who can explain Decorators in a easy and logic way..
    Thank you

  • @deepayansarkar4258
    @deepayansarkar4258 2 года назад

    This is the best explanation I found over internet

  • @kilovolt2494
    @kilovolt2494 3 года назад +10

    Let me add a remark here.
    Decorators are truly awesome because they allow modifying the function(s) on the go without rewriting them. However, what if you have a loop where the function is called, and the decorator is set to print out value every time. You will end up with a hundred printed results?
    To save yourself from it, do a little trick:
    inside the wrapper, before the return statement, declare wrapper.original = func.
    If you just call the function, it will come out decorated. If you need the original function, call func.original(), and the wrapper will return it untouched.

  • @zakariaabderrahmanesadelao3048
    @zakariaabderrahmanesadelao3048 Год назад +1

    Very grateful for your explanation. Decorators always confused me but through your detailed explanation and three very well described examples, I am more confident about decorators, thank you.

  • @yaqubadesola1839
    @yaqubadesola1839 3 года назад

    You actually deserve Nobel prize... Explanation to details

  • @floweast
    @floweast 2 года назад

    you are the only one explained the decorator clearly!!!

  • @Sciencedoneright
    @Sciencedoneright 3 года назад +77

    hey, it's Tech With Tim :O
    I was legit surprised

    • @denysivanov3364
      @denysivanov3364 3 года назад

      probably this guy copied tech with tim content....

    • @dl662
      @dl662 3 года назад +4

      This company has a shady history. They hijacked an autocomplete plug-in n defaulted users to upload their code to their servers in the backend. I ended up uninstalled autocomplete python n moved away from atom altogether. I bet they r pulling a similar trick here. So thanks but no thanks, I’m happy with Jedi n if I ever need an intelligent autocomplete tool I’ll build my own.

    • @jhonshephard921
      @jhonshephard921 3 года назад +2

      @@denysivanov3364 "this guy" is a kind-of well known code-completion company. Can be used as a plugin for VSCode.

    • @denysivanov3364
      @denysivanov3364 3 года назад +1

      @@jhonshephard921 I doubt that plugin copied Tech with Tim video =)

    • @emeraldthunder
      @emeraldthunder 3 года назад +1

      I thought the voice sounded familiar.

  • @naveenpemmana
    @naveenpemmana 5 лет назад +52

    I really loved the way you explained about the decorators. 😊

  • @LuvxJacqu4li8e
    @LuvxJacqu4li8e 2 года назад

    Nicely done. This is the first time I really paid attention to decorators

  • @Tetrick25
    @Tetrick25 4 года назад +15

    thanks for the perfect quality. Content, Voice, Speed, ...Just everything perfect

    • @KiteHQ
      @KiteHQ  4 года назад +1

      So glad to hear that!

    • @pianopianist5709
      @pianopianist5709 3 года назад

      Tech With Tim on RUclips is explaining this!

  • @justinlua4848
    @justinlua4848 2 года назад

    I've never seen that before. I knew functions were objects but I never thought to use them like that. Very well explained.

  • @shane6009
    @shane6009 2 месяца назад

    AMAZING!!! You also explained so well why *args and **kwargs are so useful and important, thank you so much!

  • @69k_gold
    @69k_gold 8 месяцев назад

    Visualization really helps here. The f1(f) was what sparked my brain there

  • @Stefadin
    @Stefadin Год назад

    Thank you for this easy to follow tutorial. For me it just clicked when you showed us the examples.

  • @wonkim7951
    @wonkim7951 10 месяцев назад

    this the best explanation about python decorator ever

  • @amanullah5858
    @amanullah5858 4 года назад +1

    was confused earlier before watching it but you covered it in the best way... really loved your video

  • @anAlokDubey
    @anAlokDubey 2 года назад

    Finally I understood the meaning of Decorators, thank you Kite :-) :-)

  • @orlanino
    @orlanino 3 года назад +1

    Explanation of how to use it and inner working, business as usual. The explanation of when and why to use it, brilliant!

  • @ISHIOYMO1
    @ISHIOYMO1 2 года назад

    You are awesome. Took me so many videos to get to this video. Now I finally understand Decorators. You make it so easy ! Thank you so much !

  • @ShahinRzayevNergiz
    @ShahinRzayevNergiz 4 года назад +3

    As of yet the best and readable explanation of the decorators in the net. Keep going, Tim, you do it best.

  • @therzook
    @therzook 3 года назад

    The minute I started Kite I knew I'd better switch it off. Not a very good thing when you forget syntax (still learning). Decorators are so confusing - trying hard to understand this stuff, watching this video every evening ;) (best video on decorators on yt, me too dumb to catch it)

  • @strawberryyogurt0
    @strawberryyogurt0 4 года назад +7

    Maybe it's just me, but the presenter using variables 'f, f1, f2' makes things visually look like a blur and took me quite a while to even grasp what he was doing. I had to use more distinct words to make things easier such as ... first_function, second_function, pass_any_function
    def first_function():
    print('from inside FIRST ')
    def second_function(pass_any_function):
    print('inside SECOND ######')
    pass_any_function()
    pass_any_function()
    pass_any_function()
    print('inside SECOND =========')
    first_function()
    print('inside SECOND =========')
    second_function(first_function)
    def third_function():
    print('inside THIRD @@@@')
    first_function()
    first_function()
    first_function()
    third_function()

    • @g2nd
      @g2nd 4 года назад

      IKR, almost all of the tutorials I watch use similar names ex. Tire, Tires. They need to be more creative with those instead of adding to the confusion.

  • @nejinii1353
    @nejinii1353 2 года назад

    Bro, Ive never seen a video tutorial where every second was clean and very precise such as yours!! Not to mention u updated my knowledghe on functions and decorators on to a whole new lelvel.
    The examples are not only great but usefull for anybody, also great tricks for our codes..
    Love you bro GREAT JOB!!!!

    • @pitchrollyawyeet
      @pitchrollyawyeet 2 года назад +1

      Go check out the maker of this videos own channel for more by him @ TechWithTim

  • @jakeambrose4294
    @jakeambrose4294 2 года назад +1

    Explained and described on a deeper level that i would think we all want to grasp to truly understand how the codes are working. Great vid. This is my first finding of your vids, now ill be looking for the rest of your stuff. Greatly appreciate anyone who adds quality contributions to education.

  • @lmg88.80
    @lmg88.80 Месяц назад

    Thank you for all the examples. I was struggling with this but now its more clear.

  • @Wolfram69756D
    @Wolfram69756D 3 года назад

    Finally a clear explanation of decorators! Many Thanks! :))

  • @siddharthupadhyay4246
    @siddharthupadhyay4246 3 года назад

    This is sooo goood. I was watching a udemy course on Python and couldnt understand the concept of decorators after multiple replays 😂 I am glad i watched this video.
    Thank You So Much:)

  • @RedexTwo
    @RedexTwo Год назад

    Thank you so much! I was struggling to understand this concept by reading resources online.

  • @michaelsvoboda1024
    @michaelsvoboda1024 4 года назад +4

    You made me begin using Kite. Thanks!

  • @jinettew.3192
    @jinettew.3192 Год назад +1

    Bravo! This was REALLY well done. You nailed it.

  • @heretolevitateme
    @heretolevitateme 4 года назад +8

    Was looking for interior design tips for my new snake and ended up here.

  • @rakeshankireddy7659
    @rakeshankireddy7659 2 года назад

    Perfect explanation. Looked at other articles and videos before but still had the confusion. This video taught the concept very clear.

  • @miyalys
    @miyalys 4 года назад

    Best decorator video I've seen so far. Thanks!

  • @jamescarroll489
    @jamescarroll489 2 года назад

    Very concise with good examples. Thanks for the brown bag!

  • @ahsenalimohammed7989
    @ahsenalimohammed7989 4 года назад +1

    Best video to understand Decorators. Really awesome explanation.

  • @thebuggser2752
    @thebuggser2752 3 года назад

    Very clear, precise and thorough presentation on decorators. Possibly the clearest I’ve seen online or in written form.
    I don’t think the concept of a decorator is a particularly intuitive one, even though Python bills itself, and usually is an intuitive programming language.. Seems to me that the Python team manufactured a construct that allows one to modify the behavior of a function without modifying the function itself.
    I’m still not sure that a decorator gives us something we couldn’t just as easily accomplished with just a few additional lines of code.
    However, still an excellent presentation. Thanks!

  • @HeavenComet
    @HeavenComet Год назад

    This is a really good decorator tutorial, understood it perfectly and helped me understand other concepts. Thank you!

  • @CraftyOldGit
    @CraftyOldGit 3 года назад +2

    This is the best explanation of decorators I have seen, thank you. Kite is an interesting idea & I will try it out, but the 'Pro' version is far too expensive.

  • @dreamou6177
    @dreamou6177 3 года назад

    很实用,面试时候对装饰器我解释的总是不太好,看了你的视频,思路清晰了。

  • @unfreshfish9472
    @unfreshfish9472 2 года назад

    Never thought an explanation like "when we call f, we actually use the variable f set to f1 with the parameter f" could be so clear. Thank you, that was a really nice lesson

  • @rawats6751
    @rawats6751 Год назад

    Thanks for your video, Now I got confidence on decorator never before. really appreciate well explained

  • @AshwinLokkur
    @AshwinLokkur 4 года назад +18

    Loved it. Quick, easy and accurate!

  • @talk9415
    @talk9415 24 дня назад

    perfectly explained, simple, easy and awesome, thank you!

  • @facts_region
    @facts_region 3 года назад

    Clean, Clear and Precise. Thanks

  • @DutchDread
    @DutchDread 3 года назад

    I'm not a programmer, but I could predict the issues, that means you did a good job explaining.

  • @kumarkumar-db3ms
    @kumarkumar-db3ms Месяц назад

    best lecture on decorators👍👍👍👍👍

  • @threejeffs
    @threejeffs 2 года назад

    Dude, you really know how break concepts down so that idiots like me can understand them. Amazing video

  • @weneverforgetwearelegion
    @weneverforgetwearelegion Год назад

    took me a full day to grasp this, thanks.

  • @philiperiskallaleal6010
    @philiperiskallaleal6010 2 года назад +3

    Dear all, thank for the amazing video. Really well explained.
    I would like to ask you a specificity regarding decorator functions. In some use cases I have come across, I noticed that the __init__ method (of some user defined classes) is used as a decorator. Nevertheless, I couldn't figure out why or under which circumstance one should use it.
    Would you be so kind as to shed some light on this regard?
    Sincerely,

  • @Ben-kz2km
    @Ben-kz2km 2 года назад +1

    Loved the examples at the end. I'm trying to figure out some best practices and cool use cases for decorators and it's really hard to find good information on when to use decorators and potential anti-patterns.

  • @brettloo7588
    @brettloo7588 2 года назад

    Excellent explanation of the topic with good pace, clarity, and concise.

  • @babygerbil
    @babygerbil 3 года назад +1

    superb explanation. topic was kinda confusing but not anymore :)

  • @lawrencedoliveiro9104
    @lawrencedoliveiro9104 3 года назад +3

    7:51 No, f1 only gets executed once, when f is defined, not every time it is called. Every time you call the result, it is the wrapper that is called.

    • @swansyboy8512
      @swansyboy8512 3 года назад

      I noticed that too, this should definitely be fixed
      We're already 2 months later though...

  • @temik26
    @temik26 3 года назад

    This videos was so helpful to me. I have watched lots of videos before I got to this detailed explanation. Thank you so much!

  • @nursultankasym8417
    @nursultankasym8417 2 года назад

    thank you man, this video helped a lot to understand the decorators

  • @ckks0nyoutube
    @ckks0nyoutube Год назад

    Thanks, helped me get python decorators, at beginner level

  • @huonglarne
    @huonglarne 2 года назад

    thanks. I love your examples, the ones that show how decorators might be used in real world situations. Very helpful

  • @rangdipkin6826
    @rangdipkin6826 2 года назад

    Awesome video! At 5:38, you would expect f1(f)() to just be equal to wrapper itself (without memory of the origin f passed into f1). The fact that f is remembered as an argument is a really important nuance called closure. That probably would have taken up more than the 15 minutes though

  • @vincenthbrennsteiner845
    @vincenthbrennsteiner845 Год назад

    This is really great, the only thing I'm not quite understanding is, how to use the function itself as well. in the timing example, what if I just want the normal function as well - do I have to copy and paste the entire function definition and change the name?

  • @Deevil992
    @Deevil992 3 года назад

    So clear. One of the best explanation on Python decorator 👍

  • @fallenstar358
    @fallenstar358 3 года назад +1

    I am grateful thank to you I can understand and use decorators in Python!

  • @staceymelnick9162
    @staceymelnick9162 3 года назад

    Great explanation of what I've thought was a convoluted subject.

  • @sjwang3892
    @sjwang3892 3 года назад

    I thank the world for having this video. God bless you

  • @svilenivanov3621
    @svilenivanov3621 Год назад

    Great and useful, Tim! Appreciated.

  • @michalwasaznik143
    @michalwasaznik143 2 года назад

    "You're definitely well on your way to becoming an expert in Python" - ngl, I nearly shed a tear.

  • @curiousMe1000
    @curiousMe1000 2 года назад

    Mind Blowing and perfect explanation. Thank you so much

  • @dominiquecolin4716
    @dominiquecolin4716 Год назад

    great job. I makes me feel I actually understood everything 😀

  • @kusocm
    @kusocm 3 года назад +2

    Regarding the 'weird behaviour' and the example of f1(f)() @6:15, if this was the goal without the funny brackets syntax, why wouldn't you redefine the definition of f1, such that it returns a called wrapper function, i.e. wrapper() instead of wrapper? That certainly eliminates the need to write f1(f)(). If someone could clarify...
    Besides that, very nice explanation.

    • @ashutoshmahapatra537
      @ashutoshmahapatra537 2 года назад +1

      Don't know if you are still interested, but here's the reason I found. The reason is arguments passed to a function. Let's say you want to pass f(2,3), If you call wrapper() then you have to provide those arguments as well but if you write wrapper(*args) it'll give error as arguments aren't passed inside the function f1. That's the reason we use that syntax so that we can pass arguments later.