Understanding Python Decorators
stackoverflow.com
Understanding Python Decorators
1–10 of 28 posts
Re: Understanding Python Decorators
#2Re: Understanding Python Decorators
#3I must say that for such a simple concept as decorator, this answer surely used up all the wireframe there ever was allocated for making examples.
Re: Understanding Python Decorators
#4Re: Understanding Python Decorators
#5I must say that for such a simple concept as decorator, this answer surely used up all the wireframe there ever was allocated for making examples.
I am pretty sure the Python community is always up for better explanations!
@foo
def bar():
...
Is syntax sugar for def bar():
...
bar = foo(bar)
That is all there is to it. It's just syntax sugar to make this particular design pattern more convenient to use.These explanations add more confusion then they dissolve and give off the impression that this is some kind of expert python foo which is clearly isn't.
Re: Understanding Python Decorators
#6I must say that for such a simple concept as decorator, this answer surely used up all the wireframe there ever was allocated for making examples.
Re: Understanding Python Decorators
#7Earlier quoted context omitted.
I am pretty sure the Python community is always up for better explanations!
Better explanations? @foo def bar(): ... Is syntax sugar for def bar(): ... bar = foo(bar) That is all there is to it. It's just syntax sugar to make this particular design pattern more convenient to use. These explanations add more confusion then they dissolve and give off the impression that this is some kind of expert python foo which is clearly isn't.
At it's most basic yes, but passing arguments to both the decorator and the decorated function are the real value of the article.
And there are examples, more than I need but they provide different ways of looking at the same thing that different people might find useful.
Re: Understanding Python Decorators
#8Earlier quoted context omitted.
I am pretty sure the Python community is always up for better explanations!
Better explanations? @foo def bar(): ... Is syntax sugar for def bar(): ... bar = foo(bar) That is all there is to it. It's just syntax sugar to make this particular design pattern more convenient to use. These explanations add more confusion then they dissolve and give off the impression that this is some kind of expert python foo which is clearly isn't.
Your answer isn't wrong, but as an exercise in pedagogy (which is the point of SO, or at least one of its major aims) it leaves a lot to be desired, and wouldn't garner many upvotes. Not everyone understands what the term "syntax sugar" (and really, shouldn't that be 'syntactic sugar'?) means.
Re: Understanding Python Decorators
#9Step 2: I bet I could ...
Step 3: Quick check of CPAN
Step 4: Zounds. http://search.cpan.org/~erwan/Python-Decorator-0.03/lib/Pyth...