The function self.cluster.execCmdVerify obviously returns an iterable, so you can simply do this:
import re
def remove_comments(line):
"""Return empty string if line begins with #."""
return re.sub(re.compile("#.*?\n" ) ,"" ,line)
return line
data = self.cluster.execCmdVerify('cat /opt/tpd/node_test/unit_test_list')
for line in data:
print remove_comments(line)
The following example is for a string output:
To be flexible, you can create a file-like object from the a string (as far as it is a string)
from cStringIO import StringIO
import re
def remove_comments(line):
"""Return empty string if line begins with #."""
return re.sub(re.compile("#.*?\n" ) ,"" ,line)
return line
data = self.cluster.execCmdVerify('cat /opt/tpd/node_test/unit_test_list')
data_file = StringIO(data)
while True:
line = data_file.read()
print remove_comments(line)
if len(line) == 0:
break
Or just use remove_comments() in your for-loop.