[Tutor] basic decorator question

boB Stepp robertvstepp at gmail.com
Wed Jul 26 22:22:59 EDT 2017


On Mon, Jul 24, 2017 at 11:01 AM, Steven D'Aprano <steve at pearwood.info> wrote:

>
> There's more to decorators than that, but hopefully that will
> demonstrate some of the basic concepts. Feel free to ask any more
> questions on the mailing list, and we will answer if we can.
>

I hope I can ask questions, too!  ~(:>))

I am having a recurring problem with Python:  I can work out the
mechanics of how various Python constructs work, such as decorators,
but then I find myself scratching my head as to why would I want to
use them.  The idea of replacing a function with its decorated version
sounds cool, but what types of problems would I want to use this
approach on?

One thing that bothers me, is that once I decorate the function, I no
longer have access to the original, un-decorated function.  But on the
other hand, if I had a decorator which I wanted to apply to multiple
functions, then I would be DRY-er by taking this approach -- I would
need only one decorator function and could then use it decorate as
many other functions as it made sense to do so.

So some guidance, please, on what types of problems this approach is useful for?

TIA!

-- 
boB


More information about the Tutor mailing list