Teaching python decoratorsby Rob Galanakis on 5/11/2012
A few weeks ago, I held a demo about context managers and decorators. Teaching context managers was straightforward, as expected. Decorators, however, are a much more complex concept. So I used Steve Ferg’s article about the right way to explain python decorators. This was a live demo with little preparation (just wrote down his steps and knew I would write decorators to cache and timeout), to a variety of skill levels, and it was unanimously successful. Everyone came away with a much clearer idea of how decorators work- I saw a lightbulb go off in everyone’s head.
I don’t know why it took so long to figure out how to teach decorators (even harder than first figuring out how to use them!), but Steve’s method works, and I’d encourage you to use it to teach anyone who’s firstname.lastname@example.org