import re
def test ( var ):
op="""
1/1/1/1 up up :99005 53476 99005 g993-2-17a
1/1/1/2 up up :99005 53148 99005 g993-2-17a
1/1/1/3 up up :99005 53793 99005 g993-2-17a
"""
op=op.splitlines()
for line in op:
pattern = "([0-9]+/[0-9]+/[0-9]+/[0-9]+) *?([a-z]+) *?([a-z]+) :([0-9]+) +?([0-9]+) +?([0-9]+) +?([a-z0-9-]+)"
if re.search(pattern, line):
match=re.search(pattern, line)
var1=re.sub(r'/', '_', match.group(1))
x = var+"_"+ var1
print x
if_index = match.group(1)
adm_state = match.group(2)
exec("global %s" % (x))
exec("%s = {}" % (x))
exec("%s['whole']=match.group(0)" % (x))
exec("%s['if_index']=match.group(1)" % (x))
exec("%s['adm_state']=match.group(2)" % (x))
exec("%s['opr_state']=match.group(3)" % (x))
exec("%s['tx_rate_us']=match.group(5)" % (x))
exec("%s['tx_rate_ds']=match.group(6)" % (x))
exec("%s['op_mode']=match.group(7)" % (x))
print info_1_1_1_1['if_index']
test("info")
print info_1_1_1_1
Hi everyone am new to python and scripting. The above one is my script and my aim is creating multiple dictionary and assigning key and value pair for the corresponding dictionary. For each line i wanted to create separate dictionary. And i wanted to to the dictionary with the same name from global space. If anything not clear let me correct it.
In global space i wanted to access dictionary like info_1_1_1_1['whole']