Python Decorators: Gift or Poison?

Loading

Upvotes: DownVotes:
Age: a year     Page Views: 378
Votes / View: 3    Wilson Score: 0.49




Why would you ever need to use decorators in Python? Have you ever hadthe task when you need to use one function in few places and you reallywanted to avoid of code duplicating? For example to add some logginginto functions or timers, etc. Decorators in Python are super powerfulwith these tasks, but at the same time they are super complicated,sometimes even magical. When I started learning Python, Decorators werereally like a magic: how to use them, how are they working, lots ofquestions. The goal is to make the things easier and clear to answer aquestion: to use or not to use Decorators in your project.