I got the following piece of information as a sequence of strings:
OPEN_MODE LOG_MODE
-------------------- ------------
MOUNTED NOARCHIVELOG
INSTANCE_NAME STATUS DATABASE_STATUS
---------------- ------------ -----------------
name MOUNTED ACTIVE
I need to get the output nicely aligned as:
Name: 'orcl', Status: 'MOUNTED', State: 'ACTIVE', Log: 'NOARCHIVELOG'
What I had tried is:
lst = []
for i in range(0, len(result.splitlines())):
if 'DATABASE_STATUS' in result.splitlines()[i]:
m1 = re.findall(r'\b\w+\b', ''.join(result.splitlines()[i+2]))
lst.append(m1)
if 'OPEN_MODE' in result.splitlines()[i]:
m2 = re.findall(r'\b\w+\b', ''.join(result.splitlines()[i+2]))
lst.append(m2)
Since my 2 if statements do differ only by the string I am looking for in the output can these be combined in 1 statement instead?
I had tried
if 'DATABASE_STATUS' in result.splitlines()[i] or 'OPEN_MODE' in result.splitlines()[i]:
and
if ('DATABASE_STATUS', 'OPEN_MODE') in result.splitlines()[i]:
but no luck.
Aucun commentaire:
Enregistrer un commentaire