import math
# First of all, Frame_Section should contain the following. Otherwise, you'll have
# to seach for your elements in the lists
# for elt in list:
# if elt[0]='MAT':
# result=elt[1]
# This way is far better
Frame_Section={'CON450X450': {'MAT':'CONC2', 'SH':'R', 'T':'.45,.45'},
'B400': {'MAT':'CONC2', 'SH':'R', 'T':'.16,.4'},
'FSEC1': {'MAT':'CON3', 'SH':'P', 'T':'.3048'},
'B400H': {'MAT':'CONC2', 'SH':'R', 'T':'.16,.4'},
'B200': {'MAT':'CONC2', 'SH':'R', 'T':'.16,.2'},
'B300': {'MAT':'CONC2', 'SH':'R', 'T':'.16,.3'}}
resline="56 J=7224,164 SEC=CON450X450 ANG=45"
targetlines=["*beam section,section=R, elset=%s,material=%s",
"%s",
"%f, %f"]
dResult={}
# Store your resline elements in a dictionary
# 1st we split using the spaces
for elt in resline.split():
keyValue=elt.split("=") # We separate the key from the value
# and store them in a tempo list
if len(keyValue)==2:
dResult[keyValue[0]]=keyValue[1]
try:
mat=Frame_Section[dResult['SEC']]['MAT'] # we get the MAT value
# And the T values
T=Frame_Section[dResult['SEC']]['T'].replace(".","0.") # To be simple,
# I do as if your floats always begin with a "." (less than 1)
resultlines=[targetlines[0] % (dResult['SEC'], mat),
targetlines[1] % T,
targetlines[2] % (math.sin(float(dResult['ANG'])*math.pi/180), math.cos(float(dResult['ANG'])*math.pi/180))]
except KeyError:
print "%s doesn't exist" % dResult['SEC']
for line in resultlines:
print line