Feb-20-2018, 11:08 AM
Wavic, Buran.... thanks for you valuable time and support and encouragement to learn python.
I am trying to parse output through below code, is this good way? but still stuck
I am trying to parse output through below code, is this good way? but still stuck
data = iter(output.split('\n')) try: for line in data: if "dishash all" in line: #skipping line with dishash all command next(data) if line == ' ': #skipping blank line next(data) else: for line in data.split('\n')[4:-2]: data = [field.strip() for field in line.split('|')[:3]] mac = [elm for elm in data[0].split() if elm] if line == '': #skipping last blank line next(data) if 'Total' in line: #skipping line with Total number of MAC addresses next(data) else: mac_addr = '{:0>2}:{:0>2}:{:0>2}:{:0>2}:{:0>2}:{:0>2}'.format(*mac) bport, vlan = data[1:] print("{:^23}\t{:^5}\t{:^5}".format(mac, bport, vlan)) except StopIteration:
Error:Traceback (most recent call last):
File "ecicollector-1.py", line 44, in <module>
for line in data.split('\n')[4:-2]:
AttributeError: 'listiterator' object has no attribute 'split'