Book notes: Maya Python for Games and Film

P34: In Python, variables are just names that point to data. All data are objects and each object has an identity, a type, and a value.

P35: Tuples, strings, and numbers are immutable. When you assign a new integer value to a variable, instead of changing the underlying value of the object to which the variable is pointing, the variable instead points to another piece of data.

P72: The asterisk(*) operator, when prefixed in front of an argument, instructs the Python interpreter to pack all of the arguments passed to the function into a tuple and to pass the tuple to the function, as opposed to passing each argument individually…It can also be used in the function call to unpack a sequence type and use the result as positional arguments.

P76: Special Python syntax to unpack each individual list item in a separate variable:
cube_xform, cube_shape = maya.cmds.polyCube()

P89: The not keyword is most often used to test against what is called an implicit false. There are certain values in Python that can be evaluated as Booleans and will return a value of False. The most common of these include “empty” values, such as (), None, [], and ”.
if len(a_list)==0  can be written as  if not a_list

P93: List comprehensions take the following basic form.
[expression_or_element for element in sequence if condition]

P125: The first time you import a module, a corresponding .pyc file will be generated. This .pyc file consists of bytecode that the interpreter actually reads at execution time. All subsequent importations of the module during a single session will reference the compiled bytecode if it exists. reload() will recompile the bytecode for the module you pass as an argument. Calling reload() in one namespace will not affect existing instances of the module in other namespaces.

P128-139: Different ways to manipulate Python search path.
Temporarily: executing the following line in the Script Editor

Consistently: creating a userSetup script, creating a sitecustomize module, and configuring an environment variable.

Leave a Reply