One thing to maybe mention Chris, is that while list comprehensions take
up less lines, the quick readability may diminish. If you have lots of
them lined up next to each other or used consecutively it can be very
hard to read the code. Especially if it isn't your own.
It's a balance of use and readability.
Eric T.
On 3/5/2015 2:55 PM, Chris Lesage wrote:
"One of the reasons that I like to use PyMel is that when you create
an object you get a reference to that object and you are not dependent
of the name when you want to find the object."
Yes, I agree. Well, in this case, you are dependent on the name. Or
you cause a bug. :)
Also I couldn't resist writing this as list comprehensions. Doing it
this way stores your locators as a list of objects that you can
reference even after your range(10) is complete.
locators = [pm.spaceLocator(n='test#') for x in range(10)]
groups = [pm.group(loc, n='group#') for loc in locators]
By the way, zfill() is a nice way to give number padding when making a
numbered naming convention. This would make test_000, test_001,
test_002, etc. ...But this will still cause a nodeError if you don't
have unique names:
locators = [pm.spaceLocator(n='test_{0}'.format(str(x).zfill(3))) for
x in range(10)]
groups = [pm.group(loc, n='group#') for loc in locators]
--
You received this message because you are subscribed to the Google Groups "Python
Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/54F8B5CD.1010009%40hybride.com.
For more options, visit https://groups.google.com/d/optout.