It also helps if you declare the dictionary :) (That's what I get for
typing on the fly when I'm about to crash for the night)--here's the
corrected code:
import maya.cmds as cmds
import string
fingers = ["index", "middle", "ring", "pinky", "thumb"]
allTheLetters = string.uppercase
namedFingers = {}
for finger in fingers:
for letter in range(4):
namedFingers["{0}{1}".format(finger, allTheLetters[letter])] =
"{0}{1}_".format(finger, allTheLetters[letter])
On 3/12/2014 12:42 AM, Joe Weidenbach wrote:
I've done exactly this! I don't know about variables directly, but
this does seem like a ready-made task for a dictionary.
Try this (I haven't tested it, but can dig in my code if it doesn't
work):
import maya.cmds as cmds
import string
fingers = ["index", "middle", "ring", "pinky", "thumb"]
allTheLetters = string.uppercase
for finger in fingers:
for letter in range(4):
namedFingers["{0}{1}".format(finger, allTheLetters[letter])] =
"{0}{1}_".format(finger, allTheLetters[letter])
I think your version of string handling should work too, I'm just very
rusty on that method.
Once you have this dictionary, you can just iterate through the keys
to get what you're looking for :)
Joe
On 3/12/2014 12:09 AM, [email protected] wrote:
I am trying to make variables with variables in their name. Is there
any way to this? Or a better way. Right now I'm getting "# Error:
can't assign to operator # SyntaxError: can't assign to operator #."
This is a simple case but it will get much longer and I'd rather not
have to have a big list of variables.
"""
import maya.cmds as cmds
import string
fingers = ["index", "middle", "ring", "pinky", "thumb"]
allTheLetters = string.uppercase
for finger in fingers:
for letter in range(4):
"%s%s" % (finger, allTheLetters[letter]) = "%s%s_" %
(finger, allTheLetters[letter])
"""
--
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/5320105A.4020501%40gmail.com.
For more options, visit https://groups.google.com/d/optout.