PLEASE Use These 5 Python Decorators

Sdílet
Vložit
  • čas přidán 12. 06. 2024
  • In this tutorial, I'll be unveiling 5 essential Python decorators that every programmer should have in their toolkit. If you're wondering what decorators are and how they can supercharge your Python code, you're in the right place. Throughout this video, I'll dive deep into the world of decorators, explaining their fundamental principles and showcasing real-world examples of how they can streamline your code and make it more efficient.
    If you want to land a developer job check out my program with Course Careers: techwithtim.net/dev
    Skool community for free resources: www.skool.com/software-develo...
    Discord server: / discord
    🎞 Video Resources 🎞
    Python Decorators Tutorial: • Expert Python Tutorial...
    Python Dataclasses Tutorial: • Python Data Classes Ar...
    ⏳ Timestamps ⏳
    00:00 | What Is A Decorator?
    05:30 | What You NEED To Know
    06:14 | @property
    10:34 | @staticmethod
    12:10 | @classmethod
    13:45 | @functools.cache
    17:09 | @dataclass
    Hashtags
    #TechWithTim
    #PythonDecorators
    #PythonProgramming
    #CodingTips

Komentáře • 66

  • @TechWithTim
    @TechWithTim  Před 2 měsíci +5

    If you’re serious about becoming a developer in 2024 check this out: techwithtim.net/dev

    • @pietrovalentinoyannellihan3883
      @pietrovalentinoyannellihan3883 Před 2 měsíci +1

      Hello, sorry to put this comment here but i need help with my flask app, im trying to put my app in an Ubuntu server but im using plesk, i already followed your instructions in your video about It but It doesnt work, this is my first website so im clueless and i would really appreciate some help

  • @kameroongod
    @kameroongod Před 2 měsíci +53

    The more I learn the more I realize I know nothing lol. Keep up the content. Few channels that gets me listening to tutorial videos in my spare time just for fun lol.

    • @franco-gil
      @franco-gil Před 2 měsíci

      The more you learn, the more you can assist others, keep learning new things. A secret, replicate all the content you are trying to learn, you will understand in a more easy way.

  • @alimihakeem841
    @alimihakeem841 Před 2 měsíci +1

    I love your content Tim. Keep it up. I have really learnt alot from you. I see as you as my role model

  • @neurooted
    @neurooted Před 2 měsíci

    Keep it up Tim! Very very high quality video.

  • @Dot_Starshot
    @Dot_Starshot Před 2 měsíci +1

    So excited to watch this!!

  • @samukaze5810
    @samukaze5810 Před 2 měsíci +1

    Tech With Tim I love your informative videos!

  • @jornjat
    @jornjat Před 25 dny

    Thank you very much! Truly enlightening!

  • @JorgeEscobarMX
    @JorgeEscobarMX Před 14 dny

    This is an excellent video about decorators, I never created my own data classes with methods, but I do use the @dataclass decorator and never knew all what comes with it.

  • @Al_Miqdad_
    @Al_Miqdad_ Před 2 měsíci

    cool information
    thank you
    ❤❤

  • @Musaafir-ln6feet
    @Musaafir-ln6feet Před 2 měsíci

    Nice can you also cover descriptors and Enums in detail they improve on dataclass.

  • @sanukyadav
    @sanukyadav Před měsícem +2

    7.18 using '_' single underscore represents protected item not private, "__" this is private.

  • @BobbyConquest
    @BobbyConquest Před 2 měsíci

    15:41 how do you type/ make those lines in the comment? Super clean. Love all your videos Tim, you have a gift for teaching

  • @Abdullo_1124
    @Abdullo_1124 Před 2 měsíci

    Thank you bro

  • @DrDeuteron
    @DrDeuteron Před měsícem

    I like functool's total_ordering decorator.

  • @mattmarshall1834
    @mattmarshall1834 Před měsícem

    The functools cache speeding up the Fibonacci func is crazy. I know how it works but it's still crazy to see.

  • @davidmurphy563
    @davidmurphy563 Před 2 měsíci +10

    Ok, we've got python decorators - but when are we getting python painters?

  • @GasterLab
    @GasterLab Před 10 hodinami

    I wouldn't say that using @dataclass decorator benefits in python coding. Because code generated by using exec() not cached where dataclass is using this by default. So, because of that. If there are a lot of dataclasses python programm will load slower

  • @grmrcy
    @grmrcy Před 2 měsíci +1

    Loved the video, but with all due respect: there is an error in the Fibonacci code. For initial conditions it should be if n < 2, return 1 (not n, as it will return 0 for n=0, but fibonacci(0) should be 1)

    • @sri_harsha_dv
      @sri_harsha_dv Před 2 měsíci +2

      It all depends on how you want to start the fibonacci series. Series can either start with (0,1) or (1,1) or (1,2), all of them lead to same sequence starting at different positions. And the time complexity barely changes.

  • @abdallahbabeker3324
    @abdallahbabeker3324 Před 2 měsíci

    Thanks for the video ❤ what's the name of your theme in vs code

  • @hieu8276
    @hieu8276 Před 2 měsíci +2

    Nice video. It enhances my belief that freshers should start with C++ or Java. Understanding the decorator, design patterns, static vs class methods, access control, and other OOP concepts makes people write better Python code. Starting with Python should only work for non-IT who need to function quickly.

    • @blazkowicz666
      @blazkowicz666 Před měsícem

      You are right. I feel in school or college, people should really try to learn:
      C to learn how a computer actually works
      Java to really understand OOP, Generics, Reflection etc.
      And C++ to implement concepts learnt from C and Java to create performant software

  • @anubhav12qw
    @anubhav12qw Před 2 měsíci +1

    Nice video bro 😊

  • @Abdullo_1124
    @Abdullo_1124 Před 2 měsíci

    plz make a pygame full course video

  • @iuritorres
    @iuritorres Před měsícem +1

    someone can give me more examples of when dataclass will be more useful than normal classes?

    • @DrDeuteron
      @DrDeuteron Před měsícem +1

      for me, when I'm reading 545 data fields of space craft telemetry, which is a helluva dunder init. Instead I just cut and paste the attributes from an excel file into a data class and it calls for a single mouse click. Moreover, dataclass comes with "fields", which can be used to describe the fields, the LaTex formulas for them. expected ranges, alarm ranges, broke ranges, and there is an astuple functions, which can be stuck in dunder iter, possible zip with the fields, and in about 3 lines of executable code, you can flag out-of-range telemetry. Very little dynamic code, and lots of static could is much simpler and less bug prone.

  • @Balkac
    @Balkac Před 2 měsíci

    This cache decorator!

  • @sinaorojlo5980
    @sinaorojlo5980 Před měsícem

    Awsome 🎉🎉❤

  • @willk4481
    @willk4481 Před měsícem

    Why do we use decorator? @4:31 mark? We could simply write another function and call the example function from within it. Add start_time and end_time above and below the function call to example function. Thatbwould be sufficient, isnit not so?

    • @rupen42
      @rupen42 Před měsícem

      Yes, that is sufficient _in this case_. But what if you want to time 5 functions? 20 functions? 100 functions? You can write 1 decorator and apply it to them all or write n individual functions for all of them.

  • @garfield-pro
    @garfield-pro Před 2 měsíci +1

    9:31 What would happen if we try to assign some value to c.diameter?

    •  Před měsícem

      Error - no setter defined.

    • @DrDeuteron
      @DrDeuteron Před měsícem

      and if you do have the bad habit of assigning attributes outside of dunder init, you can use the setter to flag when it happens, so you can find the inevitable bug caused by that bad habit.

  • @balloney2175
    @balloney2175 Před 2 měsíci +1

    Tim is da python expert. I'm afraid of pythons.

  • @cfwebdeveloper
    @cfwebdeveloper Před 2 měsíci

    May we use setter/getter in django? Probably yes? If using models can this be used? Maybe as custom validators probably? My brain just wrote this out lol but seems feasible?

    • @DrDeuteron
      @DrDeuteron Před měsícem

      what do you mean getters/setter? property and property().setter, yes, but if you're writing methods called set_radius(self, radius) or get_radius(self), then no. Never. It's not java.

    • @cfwebdeveloper
      @cfwebdeveloper Před měsícem

      @@DrDeuteron Totally agree. I also don't touch Java, ever lol

    • @DrDeuteron
      @DrDeuteron Před měsícem

      omg, I was on a NASA code project and it was full of:
      space_craft . get_intrument() . get_sensor . get_channel() . get_shelves() . get_shelf()
      . get_temperature()
      (and setters like that!)
      calls, and the 1st thing I did was turn it all in to @property and dunder getattr / init magic, (they were doing bare init class with post attribute setters), oh, and they had one class per module...so they came in Monday freaking out "85% of the code base is gone!"
      I raised my hand and said "you're welcome".
      It was pretty rocky after that ;-)

    • @cfwebdeveloper
      @cfwebdeveloper Před měsícem

      @@DrDeuteron jesus lol

  • @maamounhajnajeeb209
    @maamounhajnajeeb209 Před 16 dny

    what is the theme name please?

  • @franco-gil
    @franco-gil Před 2 měsíci

    [9:02] zero is not a positive number, it is a neutral number, you should improve the ‘if’ statement, nice video 👋

  • @Dd-do-and-dont
    @Dd-do-and-dont Před 2 měsíci

    0:17 function, method or class

  • @philtoa334
    @philtoa334 Před 2 měsíci

  • @monishbiswas1966
    @monishbiswas1966 Před 2 měsíci

    Of course you’d never write a recursive Fibonacci function like that - you’d get it to return the last two numbers so you only need one recursive call.

  • @salarbahador1270
    @salarbahador1270 Před 2 měsíci +2

    Which programming language doesn't support access modifiers these days? Do you think a convention stops people from wrongly using the methods or properties? Besides Python also doesn't support Interfaces. I'm not sure what's all the fuss about. Even modern PHP is more standard than Python; which people advertise PHP is dead.

    • @rupen42
      @rupen42 Před měsícem

      Python is a language for consenting adults. Not sure what you mean by not supporting interfaces, since untyped Python obviously doesn't have them, and type-annotated Python definitely has them (protocols). There are also abcs (abstract base classes) that serve a similar function _and_ are checked at runtime.

  • @miyu545
    @miyu545 Před měsícem

    I think the rocket scientist that thought about how or why to create decorators were drunked sailores full time, programmers part time.

  • @johngeverett
    @johngeverett Před měsícem

    So you implement privatization schema to 'fix' the deficiency of Python in having all public attributes and methods. Also adding 'hints' to variable definitions to make up for the type-agnostic nature of the language. Next "awesome best language ever" coming soon to a computer near you!

    • @Nova32x
      @Nova32x Před měsícem

      Not really sure what you're point is. The main use case of the property abstraction of a private variable is for libraries. No reason for actual strict access control. Also type hints are mostly for runtime type checking and editors.

  • @Smallz2000i
    @Smallz2000i Před 2 měsíci

    slowprint lol

  • @hasithkashyapa7645
    @hasithkashyapa7645 Před 2 měsíci +2

    Ok i saw the same thing few days ago. So this is basically a copy.

  • @Al_Miqdad_
    @Al_Miqdad_ Před 2 měsíci

    can you give me your course for free and I'll pay after I get job please ?
    I don't have a job

  • @z.8477
    @z.8477 Před 2 měsíci +1

    PLEASE DO NOT Use These ANKWARD FACES

  • @publicuser775
    @publicuser775 Před 2 měsíci

    Hate this click bites

  • @glych002
    @glych002 Před měsícem

    Please don’t use python

  • @davidmurphy563
    @davidmurphy563 Před 2 měsíci +1

    Just googled !r, it returns the repr in an f-string! And !s will give you dunder str. I had no idea this was a thing!
    Learned something new today.