02 Story - Python Decorators Importance

2 minutes
Share the link to this page
Copied
  Completed
In this video, you will listen to a story demonstrating the importance of decorators and how useful it could be in real-life scenarios.

Transcript

Hey there, this is commanda, your facilitator for the scores decorators in Python. Python decorators are very useful because it adds or modify functionality of an existing function method or classes. But there's a big question, why should I learn this decorators in Python? Why should I master it? Let's understand this in the form of a story. Imagine you have got 50 functions with business logic in your report generating program.

On a very beautiful morning, at the start of the week, your boss walks up to your desk and says, Happy Monday. Remember those transaction processing reports. I need you to add input output logging to each step in your generator report. In the report generator XYZ Corporation needed for auditing purposes. Oh, I told them, we can ship this by Bannister. Depending on whether or not you have got a solid grasp on Python decorators, this request will either send your blood pressure's spiking or leave you relatively calm and comfortable.

Without decorators, you might be spending the next three days scrambling to modify each of those 50 functions and clutter them up with manual login calls. But fun times, now, if you do know your decorators, you will come to smile at your boss and say, Don't worry, relax. I'll get it done by 2pm today, right after that you'll type the code of for a generic audit log decorator. That's only about 10 lines long and quickly paste it in front of each function definition. Then you will commit your code and grab another cup of coffee that simple isn't it I am dramatizing here, but only a little decorators that can be that powerful. I would go as far as to say that understanding decorators is a milestone for any serious Python program.

Remember, they require a solid grasp of several advanced concepts in the language including the properties of first class functions. Understanding decorators is worth it, the payoff of understanding how decorators work in Python is huge. In the next video, we'll be discussing on how now I know you will definitely would like and love to understand and know more about decorators in Python. So in the upcoming video, we'll be discussing the syntax of decorators in simple and in a way that builds your concepts slowly and smoothly. Thank you. Hope to see you in the next video.

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.