Python: list of tuples without "

I am trying to use the Abaqus scripting interface (commercial FEA code) to create FE models, although my question is specific to Python, but it reminds me a bit of why I'm trying to do this.

Abaqus has a built-in logical merge operation that requires the use of the following syntax:

a.InstanceFromBooleanMerge(name='name_string', instances=(
    a.instances['string1'], a.instances['string2'], 
    a.instances['string3'], ), originalInstances=SUPPRESS, 
    domain=GEOMETRY)

The instances parameter is specified as a tuple, where each element has a format

a.instances['string1']

I am trying to make the number of elements inside this tuple and, obviously, the names inside it are scriptable. I currently have code that looks like this:

my_list = []
for i in range(4):
    name = str('a.instances[\'')+str('name_')+str(i)+str('\']')
    my_list.append(name)
my_list = tuple(my_list)
print my_list

However, this gives:

("a.instances['name_0']", "a.instances['name_1']", "a.instances['name_2']",   
    a.instances['name_3']")

lstrip rstrip "", . , ? Abaqus, , .

+3
2

, :

for i in range(4):
    val = a.instances["name_"+str(i)]
    my_list.append(val)

, :

my_list = tuple(a.instances["name_"+str(i)] for i in range(4))
+3

, - , , (123,) ("123",). , :

def make_tuple_of(n):
    return '(' + ', '.join("a.instances['name_" + str(i) + "']" for i in range(n)) + ')'

: , , . - , , tuple(a.instances['name_' + str(i)] for i in range(n))

Edit2: , . - , , . , [a.instances['name_' + str(i)] for i in range(n)] .

+1

All Articles