O'Reilly logo

Practical Maya Programming with Python by Robert Galanakis

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Introducing decorators

Decorators are the single most unfortunately explained language feature of Python. An improved way to teach decorators was presented by Steve Ferg on his blog: http://pythonconquerstheuniverse.wordpress.com/2012/04/29/python-decorators/. I've adapted his suggestions for use in this section.

Decorators associate setup and teardown functionality with some callable object. In the preceding example, we associated the functionality of "each time some function is called, it can be undone as a single block" with the makefoot function. There is no way to call makefoot without this new behavior added by the decorator.

Explaining decorators

I find it easiest to explain decorators by working from very basic Python and eventually ending ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required