Expert Python Tutorial #4 - Decorators

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

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

  • @deadweightyeti7002
    @deadweightyeti7002 Год назад +13

    I've been wanting to reach the next level but documentation is too confusing. These videos have been helping me a ton!

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

      Thanks so much for the donation!

  • @VictorCaldo
    @VictorCaldo 4 года назад +20

    I think I can finally incorporate them into my code! As a self-taught Biotech your content does all the difference, thank you!

  • @chethancheths4198
    @chethancheths4198 4 года назад +17

    The best tutorial for getting into expert zone
    Kindly Dont miss to teach us about threading ♥️

  • @erickalvarez6486
    @erickalvarez6486 4 года назад +28

    Geez never thought I'd learn this much from a RUclips video, did not regret of subscribing, thanks a lot, now I understand more

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

    This is by far my favorite series from you :) this covers exactly what I’ve been meaning to learn but just haven’t gotten around to in python! Thanks so much!

  • @hackerzone2002
    @hackerzone2002 12 дней назад

    Really it was amazing Video I was very confused in decorator after watching your video my all concepts got cleared and not about decorators i have watched your most of the lecture and the only thing which i wan't to say is all are amazing the content you provide in your video is easy to digestible . Thank you tim ☺

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

    I love your teaching style. It is at such a level that it is easy to follow, while still being able to teach all the content. Your channel is a prime example of what a good tutorial channel should be like.

  • @mahmoudelleithy6908
    @mahmoudelleithy6908 6 месяцев назад +1

    dont like write comments much but this one i couldn't skip not to say thank you very concise

  • @dany_fg
    @dany_fg 3 месяца назад +1

    It's extremely useful for exception catching, especially for testing (the decoratir will return test successful or failed)

  • @willet2275
    @willet2275 4 года назад +11

    Instead of showing the program syntax - I think the best tutorial is showing real, practical application programs. Variable definitions and function definitions can be found in every manual.
    What is useful, is to show the overall structure of the program: how the program is built depending on its purpose, and what part of it is responsible for. From General to specific.
    It's like learning a foreign language from a boring alphabet. There are plenty of such tutorials.
    And yet to learn a language, you can start to play specific genre scenes from real life.

  • @Lofwyrf
    @Lofwyrf 4 года назад +6

    This was so uuuuuuuuussssssssssssssefull thanks a lot. Never understood what Decoraters actualy did.

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

    Dude I feel like a python god when I learn these expert level stuff

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

    The best on the internet. I’m serious. You are precise, concise, yet still capture the relevant nuance. Never stop!

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

    The way @Tim explians all the stuff, thats incredible.

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

    Was searching for hours and hours for a perfect tutorial and this was the best!

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

    Best tutorial explaining this concept. It makes such a big difference by keeping it simple and using print statements, instead of making nonsensical convoluted stuff that I've seen other tutorials do.

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

    You always explain thing at their root! That’s why my mind loves to understand it. Thanks so much!! 😊

  • @Oscar-vs5yw
    @Oscar-vs5yw Год назад +2

    This series is really great, covers all the stuff I never bothered to learn 😢😂

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

    Realy like your videos and i don't want to be the old guy here, but mainly this is C pointers in "not so ugly" mode. There are good books on this and they really help understanding the python way on getting things done.

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

    Thank you. I've been using them in my latest project, a discord bot, and I haven't really though about how they work instead just taking them for granted. Now I can use them in more of my projects to hopefully speed up my code a little bit.

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

    At first I thought decorators were a mistake, now I see they can be useful. Thank you for this video.

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

    One of the very best Decorator explanations out there.

  • @andreacodutti1313
    @andreacodutti1313 4 года назад +5

    Another useful application is memoizing recursive function calls, for example for Fibonacci sequence

  • @ahmed.rosanally
    @ahmed.rosanally 4 года назад +1

    Saw decorators being used the pizza API code you've used in a previous vid series. Really interesting to see how it works, especially with *args and **kwargs

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

    Tim, you're a great teacher. Thanks a lot.

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

    A treasure trove. Ty Tim.

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

    Learned a lot of advanced stuff from your tutorial. Keep making more tutorials.

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

    Thanks a lot for your videos, you explain quite simple and user friendly, appreciate your work man, but there is a doubt I have
    what is the use of the wrapper functions?? Why don't just define operations of the function inside the main function?? Makes no sense to an amateur like me...

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

    Excellent to see your use cases here of decorators made it easy to understand because you linked to stuff covered in other video about passing a function as an argument.
    Question for you if you see this: how would you iterate over attributes of a class instance?

  • @jonathanmoore5619
    @jonathanmoore5619 19 дней назад

    Beautiful explanation. Thanks

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

    It’s one of the best explanation of decorators. Thank you!
    Also thank you for example.
    It would be great if you will show more examples. Logging for example

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

    Tim: "This is advanced Python"
    My teacher: "It's the third week of this python introduction course, let's talka about decorators!"

  • @impos1ble32
    @impos1ble32 4 года назад +2

    Awesome video, learned a lot. surprised that you did it almost perfectly in one take!

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

    Thank you, it's amazing tutorial... Never ever seen a tutorial like this.. so so good, covers all the concepts. Thank you once again :)

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

    one of the best explanation of confusing concepts like metaclasses and decorators. Thanks for awesome videos !!! :)

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

    hi tim, thanks a lot for this video , decorators concept is so clear now , best explanation, this is my first ever comment on youtube

  • @georgettebeulah4427
    @georgettebeulah4427 4 года назад +2

    This make so much sense and meaning

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

    One of the most informative tutorials!
    💯💯💯💯💯💯

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

    omg I get it now. The implicit passing of the decorated function object as a parameter kept throwing me.

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

    I love this tuts! What other expert python tuts will you make?

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

    Love your teachings bro

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

    This is kind of complicated explanation but greetings for taking the time.

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

    Loving the title "Expert Python Tutorial - Decorators". Everytime I see "Python tutorial FOR ABSOLUTE BEGINNERS" combined with something like dunder methods or decorators/getter/setter I feel like this programming thing might not be for me :D
    This at least does not make me feel like I'm completely stupid :D

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

    Thank you for this you cleared so many issues I had

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

    Listen to his voice at 12:24 haaaaaa. Good tutorial though thanks man!

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

    Nice tutorial, but it would have been clearer if you called func wrap instead and maybe func2 foo and func3 bar. That way it would have been x = wrap(foo) which is much clearer.

  • @thedevhassan
    @thedevhassan 4 года назад +2

    Kindly make a full course on Django plz

  • @FUNG36987
    @FUNG36987 4 года назад +6

    you didn't mention the implementation on decorators having their own parameters which in some cases are more generic and flexible

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

    An implicit intro to aspect oriented programming

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

    Nice videos. Found your channel not long ago and that's why the late comment. Unfortunately, for everyone using this python-included way of writing decorators, the function being wrapped looses its properties to the wrapper function. If you print for example the __name__ of the function being wrapped (i.e. with print(func2.__name__)) you will notice the name is "wrapper" instead of func2. In most cases this shouldn't make a difference for us but if you really want you can change this just a little bit and use a function included in functools called wraps (actually it is a decorator itself so you decorate your wrapper function with @wraps) and the function being decorated will retain its properties. Here's a simple example using the same logic as Tim:
    def func1(f):
    @wraps(f)
    def wrap(*args, **kwargs):
    print('begin...')
    rv = f(*args, **kwargs)
    print('end...')
    return rv
    return wrap
    @func1
    def my_func1(x, y):
    print(x)
    return y
    x = my_func1(5, 6)
    print(x)
    print(my_func1.__name__)
    Hope it helps somebody. Cheers!

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

    Nice one. You've got a new subscriber

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

    Good explanation.

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

    So many Funcs, I'm about play that music.

  • @vivekr.k7950
    @vivekr.k7950 2 года назад

    Nice explanation

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

    Really amazing thanks a lot... a clear understanding for me!!

  • @kazifaisal-rj9js
    @kazifaisal-rj9js Год назад

    Yoda !!! Thanks, really appreciate it

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

    well explained

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

    You can also decorate classes, which may let you avoid using dunder metaclass.

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

    Hey nice tutorial😊subscribed🤍
    And also which IDE r u using? Is it available in Windows?

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

    I always wait for a new video in this series.

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

    Hey Tim, just one question. What's the point of creating the wrapper function? It feels like an unnecessary step. The first example could just go without it. The problem occurs when arguments are passed to the function, but why? Can you explain please, thanks.

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

    acho q entendi decorators finalmente valeu demais mano ajudou mt tmj

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

    Well Articulated.

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

    Good one

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

    Great video.

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

    Step one write some partially copied code
    Step two, see Tim to figure out why your code works

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

    i can't thank you enough bro

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

    Hey bro. Thanks for your tutorials. You are the best

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

    I am not gonna say that i am first , even that i am . But , serriosly , thank u Tim 🙏🙏

  • @hutsons-hacks3668
    @hutsons-hacks3668 2 года назад

    Very nice 👌

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

    Thanks!

  • @AK-fr8sy
    @AK-fr8sy 2 года назад

    Legendary

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

    Great video. but it missed something important. The decorator @wraps from functools. To keep track of the information about the REAL function itself, not the decorator.
    ```
    from functools import wraps
    def timer(func):
    @wraps(func)
    def wrapper(*args, **kwargs):
    .....
    ```

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

    Nailed it

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

    learning by coding, great !

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

    Now that I've seen the decorator function used as a time an execution of the function. One of the things I can think of that could be useful for using decorators are unit tests, is it correct?
    We can write unit tests for functions so we want to cover the major outcomes of the function and if they work as expected.

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

    *Thanks Tim*

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

    I was wondering where you at. Thanks Tim

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

    0:13 actually they CAN change code of the function but generally no one needs to do that

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

    Great explanation!

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

    Just a question, why are you storing the return value (rv) in the last example? i cannot understand that part. You can just call the func, unless you wanted to make this last example universal? In case we will have some functions later where we return value?

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

    Top notch!

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

    noorandu kaalam vazhga!

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

    So, I tried running the "func(f) code without wrapper() inside, just: print("Started"), f(), print("Ended"), return. All the rest was the same and it ran perfectly, giving the same output, except after printing the output it gave an error saying "func3() ... Nonetype object is not callable." And yet I called it. And it ran fine. Why bother to throw an error at me after it already executed exactly as it should have?

  • @ahmed.rosanally
    @ahmed.rosanally 4 года назад

    You should elaborate more on how *args and **kwargs are used in a future python expert video

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

      **kwargs

    • @ahmed.rosanally
      @ahmed.rosanally 4 года назад

      they remind me of pointers in C, although they behave different conceptually

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

    What IDE is this? It looks good

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

    My man streaming Python tutorials from a Five Guys bathroom.

  • @user-uw3hu2bb4s
    @user-uw3hu2bb4s 3 года назад

    2:28
    i did the same mistake as writting () these as 90
    i thought i was the only

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

    Please Sockets in Python, Please Tim 🙂🙃

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

      Look at his online game pygame it uses sockets and threading

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

      Import socket
      s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
      s.connect (("ipaddress", port))
      s.recv(1024)
      s.send("fuckyou")
      s.close()
      Here you go socket programming

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

      @@westernvibes1267 what about handling multiple clients 🤔

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

      @@vebexplaeya copy pasta

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

    I need an answer: does the wrapper function exist because either way the decorating function would be called every time?

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

      Than i have another question: how do i interact with the arguments that are passed in the decorated function?

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

    Great series please continue, I want to ask you a qeustion about what laptop/pc do u use and what is the CPU and how many cores it has. Also I have a problem with flask when I try to write @app.route("/")
    def home():
    return render_template("index1.html")
    when I run it it displays "jinja2.exceptions.TemplateNotFound: index1.html"(with debugger on) so if u have any knowledge about this please tell me

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

      i have flask tutorials on how to render templates try watching those.

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

    I don't get the part of return wrapper, can anyone explain please?

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

    do the descriptor protocol next

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

    how it works when you apply 2 or more decorators? I mean, python applies decorators in some order?

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

    How about passing an argument to a decorator?

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

    Full Django course please ;)

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

    Personally, this does not seems on par with the rest of your material. A lot more could've been said (decorator with arguments, multiple decorators resolution order, class decorators, ....etc). Example-wise the timer is fine, but maybe a little bit over-simplistic, it is an expert tutorial after all. That said, i really appreciate all the effort you put in your videos, and found your material very useful in many occasions, so keep up the good work!
    .

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

      Appreciate the feedback!!

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

      @@TechWithTim maybe a follow-up, in-depth, video? Expanding on some topics and perhaps showing some "real-world" application use-cases. Flask and Click comes to mind (They do extensive use of decorators and could be nice to tie them up in a single project) :)

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

    do you have the code that you use in your videos ?

  • @Mondayikaebinyou
    @Mondayikaebinyou 3 месяца назад

    Okay

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

    what font is he using please ??