Summary

In this chapter, we saw how Python decorators and context managers invert the subroutine and allow us to factor out common setup and teardown code. We learned how both of these techniques work, and when to apply them. We implemented several context managers that make programming Python in Maya a better experience. We closed by exploring some potential uses for decorators, and advanced topics for future investigation.

Context managers and decorators are two powerful features that will come up again and again throughout this book and as you program Python. It is well worth understanding what they have to offer, and we've only just scratched the surface in this chapter. As convenient as they are for mapping Maya's problems onto Pythonic idioms, ...

Get Practical Maya Programming with Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.