PyMel select duplicated names

I have a Maya scene with several transform nodes with the same name (and this could not be changed), e.g. “Object_A”.

I need to select objectst:

import pymel.core as pm
list = ['Object_A', 'Object_B']

Which results in an error. What workarounds are possible?
If you type Object_A in Status Line “Select by name” the objects would be selected without errors.

Instead of passing an explicit list of strings to, list them first using

import pymel.core as pm
objects =['Object_A', 'Object_B'])
# OR
objects ='Object_A', 'Object_B')

Edit: Also don’t use “list” as a variable. That will overwrite the list keyword!

1 Like

Nice, thanks, exactly what I was looking for!

And yes, I would not have clashing names in my actual code!

You did post actual code that an actual person ran. :wink: