One of the harder concepts to learn in #Python are decorators.
So let's take a few moments and learn about them!
๐งต๐๐
So let's take a few moments and learn about them!
๐งต๐๐
But wait! #Python functions are also objects. You can get their `__name__` and their docstring (`__doc__`), if they have one.
You can also get a listing of their other methods with `dir()`
What all this means is that you can pass a function to another function!
You can also get a listing of their other methods with `dir()`
What all this means is that you can pass a function to another function!
Did you know you can pass arguments to #Python decorators?
All you need to do is create a function inside a function inside a function! ๐คฏ๐
All you need to do is create a function inside a function inside a function! ๐คฏ๐
You can also turn a class into a decorator in #Python!
To make that work, override the `__call__()` method.
I actually like this method a little better for passing arguments to a decorator as the code isn't so crazy-looking!
To make that work, override the `__call__()` method.
I actually like this method a little better for passing arguments to a decorator as the code isn't so crazy-looking!
The examples in this tweet thread are taken from my tutorial, "All About Decorators" on @mousevspython
blog.pythonlibrary.org
blog.pythonlibrary.org
@mousevspython Thanks so much for reading my series on Python decorators!
Follow me if you're interested in learning more about Python!
Follow me if you're interested in learning more about Python!
Loading suggestions...