why can’t we just pass the function in the wrapper function itself with username, password, args and kwargs?
Why do we require decorators in python at all?
Hey @stutijain578
As the mentor said, it is done to reduce redundancy (Following the DRY principle). We don’t want to repeat the same code again and again.
Also, if you mean to say why don’t we just use the syntax my_decorator(my_function)
, it is because this construct is used in many places. Hence, the creators decided to give it a special syntax to increase code readability and the decorator syntax also looks better (Consider the case of multiple decorators dec_a(dec_b(dec_c(my_function)))
, so ugly).
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.