So I’m getting into using the Python API in maya and some tools require me to iterate code over various objects. This requires attaching an object reference with it’s name to an object creator’s output, and then running a function immediately after it’s called.
Rather than running (hypothetical example):
className.myObject1 = mayaClass.create(myObject1)
func1()
func2()
className.myObject2 = mayaClass.create(myObject2)
func1()
func2()
etc..
is there a way I could say do this:
myObjs = ['myObject1','myObject2','myObject3']
for obj in myObjs:
className.obj = mayaClass.create(obj)
func1()
func2()
It would certainly save a lot of typing, shrink down the script size and make things more easily maintainable.
setattr()will set a object’s attribute (given by a string) to the specified valuevars()will get the local variables as a dictionaryHave a look at http://docs.python.org/library/functions.html for important builtins of Python
EDIT:
I noticed also another answer mentions
exec. Be careful when using this in any python code .