+ 2
Usefulness of decorators
hi guys I've search and read multiple post about decorators and I think my light bulb just lit up! I was trying to find the usefulness of the decorator and it all became clear when I started to write this post. I was asking myself why go into all this trouble if I can write one simple function that will wrap it anyway and using the decoratior on a funtion will make it unusable alone. But I wasn't asking myself the right question.
4 Antworten
+ 3
Here is an example of what a decorator may be useful for:
https://code.sololearn.com/cD09ijlIS6Ev/?ref=app
+ 2
Whoever hit minus on this could at least correct me... I mean isn't what the discussion section is about?
+ 2
Yeah, about right. I've used them to easily catch exceptions that occur during runtime, by using a simple decorator.
IGNORE
--------
What is truly disappointing, though, is that you have to have the same parameter list as the decorator in order to use it properly.
--------
IGNORE
Here's some stuff: https://code.sololearn.com/cN64JekRVno0/?ref=app
Copy and paste into the interpreter or a file and run.
0
The decorators are made to implement other function that alone a fade and lifeless so they need the decorator to be as a whole.
Someone posted this address somewhere in here (I think it was Kuba)
https://www.thecodeship.com/patterns/guide-to-JUMP_LINK__&&__python__&&__JUMP_LINK-function-decorators/
He used the decorator as tag to wrap whatever he needed so a decorator for <p>, <div>, and so on so you don't have to rewrite the decoration over and over.
Am I on the right track here?