Hey there. Hello everyone. This is your facilitator commander for this course decorators in Python. Earlier we discussed Python decorators, Introduction syntax, why it is important and how the buyten decorators work chaining decorators. And in this video, we'll be discussing debugging decorators. So let's move on.
This is just a simple decorator that they just created. It has an inner function that takes an argument and key value arguments, prints hash 50 times, and then take the decorated function into it and then prints hash 50 times returns the inner function, another function that I just another decorated function that I just created. It also has the inner function within it, print stash 50 times takes the decorated function within it. And then again, print stash. Two times. Now I just decorated the show greeting function with hash a and dash.
It was discussed earlier in the last video as well, but I'm just repeating that in order to get give you an idea of how debugging can work within with the decorators. Okay, let's execute the last decorator functions that we created. Okay, now it's executed. Now this decorator of this function that we created, it is executed. And now I'm going to use the attribute method of name with the show function that I just created. And I get inner.
Now you see within the show function, there is no enter, but it is giving me the name as inner. So, what it is actually doing and this is the kind of disadvantage of using decorator function that when we define the decorator function, actually refers to the decorator not the actual origin of the function, it should have shown me show that is the name of the function, but it is actually referring it to the decorator function that is being used. And therefore, it becomes very difficult to debug those because we don't know the origin of the function. And in that case, the become like debugging becomes very difficult. But how to solve this problem, we can solve this problem using import importing function tools library, what it does, then, why creating the decorator function, we can add the function tools dot reps, and then the function that we need to be decorated and pass it as as the parameter just like the normal decorator functions.
So what it will do, like here, we have passed a function the same way And we're going to do here. Now, after that, when we're going to debug it Are we are going to use the attribute name of the function, it is going to show us the original function instead of the decorator function. So we know actually, where the function is originating from and which are the decorators that are being applied to that. Let's execute this. Let's see, again, the same thing. I just executed this function and it is giving me error named func tool is not defined, okay, I did not import that library and that's why it is giving me this error.
So I just need to import it. Let me just execute it. Okay, now it's imported. 90 executed and see, when we run this code, it is going to show the actual name of the function that is show. Okay, this is how the decorator debugging function works. I hope now you have a better understanding of debugging and why debugging become more important that with decorators.
So may you have any queries feel free to contact me or if you have any suggestions or feedback to let me know you can get in touch with me on Twitter, YouTube, and my courses on Udemy. I also write blogs and medium so you can get in, you can get in touch with me over there as well. And it was really nice talking to you. And looking forward to see you again in the next video that will summarize the whole the whole topic of decorators. Thank you