#100DaysOfCode in Python Transcripts
Chapter: Days 22-24: Decorators
Lecture: More abstraction: stacking decorators

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Next up, let's talk about how
0:02 you can stack decorators.
0:05 And I've found an image of Russian dolls,
0:07 which might clarify how this "nesting" works.
0:12 So let's define another decorator
0:14 that shows the args and keyword args being passed in,
0:17 and we're going to stack that
0:19 together with the timeit decorator.
0:37 Alright, let's modify generate report
0:40 from the last video to take some arguments.
0:47 And now, let me show you how you can stack
0:49 the two decorators we've defined so far,
0:52 and note that the order matters.
0:55 So I put timeit as the outer decorator,
0:57 because I want to time the whole operation,
0:59 including the use of the print args decorator.
1:05 Let's now call it, but first let's
1:06 give it some parameters, so let me quickly
1:10 find a dictionary of some keyword arguments.
1:16 And now, all should come together,
1:18 because when I call generate report
1:20 with some args and some keyword args,
1:25 look at that.
1:26 We see two decorators in action.
1:28 First a timer, starting the timer,
1:30 doing stuff, ending the timer,
1:32 and printing how long it took,
1:33 and then we see the inner decorator,
1:35 print args, printing the args and the keyword args.
1:39 And here you see that decorators
1:41 can become pretty powerful, because each decorator is doing
1:44 a specific task, which can be applied
1:46 to multiple functions, yet it's all abstracted
1:49 in their definition.
1:51 And, yes, this is how you can stack decorators.