**Decorators**

Decorators are intuitive and extremely useful. To demonstrate, we’ll look at a simple example. Let’s say we’ve got some function that sums all numbers 0 to n:

def sum_0_to_n(n): count = 0 while n > 0: count += n n -= 1 return count

and we’d like to time the performance of this function. Of course we could just modify the function like so:

Continue reading “Decorators and Metaprogramming in Python”

Advertisements