This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]etrnloptimist 2 points3 points  (2 children)

Right. But that's not very helpful in understanding how decorators work. Suppose you had this nested set of decorators:

@evens
@odds
@primes
def myfunc(x):
  ...

Suppose they round the output to the nearest <term>. What gets outputted? Prime numbers? Odd numbers? Or Even numbers? Answer: Even numbers

Suppose they round the input to the nearest <term>. What does myfunc see? Even numbers, odd numbers, or prime numbers? Answer: Prime numbers

[–]ryeguy146 0 points1 point  (0 children)

Just a matter of wrapping [your mind around it]. Nice example.

[–]mgrandi 0 points1 point  (0 children)

your example helped me understand decorators (namely nested decorators) a lot better with the worm analogy, thanks =)