Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7895847
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:44:32+00:00 2026-06-03T07:44:32+00:00

How do I iterate through a list whose name will be dynamically generated? boneList_head

  • 0

How do I iterate through a list whose name will be dynamically generated?

boneList_head =['def_neck', 'def_armbase']#hard coded list
itemType='head'# result of a user button press
...
def selectBones():
    global itemType
    bones =('boneList_'+itemType)# evaluates as a string , not name of a list
    for bone in bones:
        cmds.select(bone, tgl=True)

the problem is bones is getting evaluated as a string, when I need it to evalute as the name of a list.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T07:44:33+00:00Added an answer on June 3, 2026 at 7:44 am

    Dynamically generating variable names is almost always a bad approach. Use a dictionary!

    bonedict = {'boneList_head': ['def_neck', 'def_armbase']}
    itemType='head'
    
    def selectBones(itemType):
        bones = bonedict['boneList_' + itemType]
        for bone in bones:
            cmds.select(bone, tgl=True)
    

    Please ignore my previous answer (visible in my edit history) which was stupid — boneheaded, even. But I blame its stupidity on dynamic variable name generation!

    Let me elaborate on why dynamic variable name generation is a bad idea.

    1. Because dynamic variable generation masks variable name definitions. It’s hard to tell what has been defined and what hasn’t, so it’s easy to accidentally redefine a variable. This is a major source of potential bugs.

    2. Because dynamic variable manipulation hides state changes under another layer of obfuscation. To some degree, this is true anytime you create a dictionary or a list. But one expects lists and dictionaries to demand a little extra thinking. Variable names, on the other hand, should be dead simple. When variable definitions and redefinitions require deep thought to understand, something is wrong.

    3. Because dynamic variable generation pollutes the namespace. If you have so many variables that you have to automatically generate them, then they should live in their own namespace, not in the locals of a function, and definitely not in the global namespace. In his style guide for the linux kernel, Linus Torvalds advises that if a function has more than 5-10 local variables, you’re doing something wrong.

    4. Because dynamic variable generation contributes to high coupling, which is a bad thing. If you assign to values to a dictionary, you can pass that dictionary back and forth until the cows come home, and all anyone has to know about is that dictionary. If you dynamically create variable names in the global namespace of a module, then if another module wants to access those variable names, it has to know all about the way they were generated, what other variables in that module are defined, and so on. Also, passing the variables around becomes much more complex — you have to pass around a reference to the module itself, probably using sys.modules or other questionable constructs.

    5. Because dynamic variable generation is ugly. eval looks neat and clean, but it really isn’t. It can do anything. Functions that can do anything are bad, because you can’t tell at first glance what they’re doing here. A well-defined function does one thing, and does it well; that way, whenever you see that function, you know exactly what’s happening. When you see eval, literally anything could be happening. In this sense, eval is like goto. The problem with goto is not that you can’t use it correctly; it’s that for every possible correct use of goto, there are 500,000,000 terrifyingly wrong ways to use it. I won’t even discuss the security problems here, because in the end, that’s not the real problem with eval.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does map() iterate through the list like for would? Is there a value in
Is it slower to iterate through a list in Java like this: for (int
I want to iterate through a list of files without caring about what characters
I am trying to iterate through a list of float widths that varies. [10.5,
I have a List and I want to iterate through the list and draw
I am trying to iterate through a list and take each part of the
I have a powershell script to iterate through a list of LinkedServer objects in
I am using a for loop to iterate through a list of arrays that
Is there is some good way to iterate through list in django template and
I'm trying to iterate through a list of folders, but I can't seem to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.