I am trying to write sample code which will read from a file but a)Ignore empty line b) will only show lines which starts with dm- but its giving me error, not sure what to do , can any one please give me some light
def _find_dm_name():
with open (IOSTAT_OUTPUT,'r')as f:
for line in f:
lines = (line.rstrip() for line in f)
lines = list(line for line in lines if line)
if re.match("(dm-)", lines):
content=lines
return content
if __name__ == '__main__':
dm_name=_find_dm_name()
print dm_name
Traceback (most recent call last):
File "test.py", line 47, in <module>
dm_name=_find_dm_name()
File "test.py", line 41, in _find_dm_name
if re.match("(.*)", lines):
File "/usr/lib64/python2.6/re.py", line 137, in match
return _compile(pattern, flags).match(string)
TypeError: expected string or buffer
Even though if i try this
def _find_dm_name():
with open (IOSTAT_OUTPUT,'r')as f:
for line in f:
if re.match("(dm-*)", line):
content=line
return content
it gives me only the last line
but how do I get all the line which match only dm- + ignore any empty lines