Book Image

Practical Maya Programming with Python

By : Robert Galanakis
Book Image

Practical Maya Programming with Python

By: Robert Galanakis

Overview of this book

Table of Contents (17 chapters)
Practical Maya Programming with Python
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Chapter 4. Leveraging Context Managers and Decorators in Maya

Context managers and decorators are two Python features that open up many powerful programming patterns. Many of these end up being incredibly useful in Maya, allowing us to map the archaic, imperative style of Maya command calls onto Pythonic code using flexible, modern idioms.

In this chapter, we will learn what context managers and decorators are, why they are useful, how they work, and when to use one instead of the other. After that, we'll build a number of simple context managers for safely modifying scene state. Using what we've learned, we will work on two projects: a context manager for denormalizing vertex skinning, and a decorator to record metrics. We will close out the chapter by analyzing some advanced decorator topics.