namedtuple help - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: namedtuple help (/thread-21865.html) |
namedtuple help - anna - Oct-18-2019 Hi All, something is going wrong and not able to understand. below code is polling lag interface details. I am not able to print using namedtuple. tLagOperationEntry_list = [] for host in my_devices: try: session = Session(hostname=host, community='cacti', version=2) except easysnmp.EasySNMPConnectionError as e: print('Error:- {}'.format(e)) sys.exit(1) try: tLagIfIndex,tLagConfigLastChange,tLagLACPPrimaryPort\ = (list(session.bulkwalk('1.3.6.1.4.1.6527.3.1.2.15.3.1.'+c, \ non_repeaters=0, max_repetitions=50))for c in ('1','2','5')) except easysnmp.EasySNMPNoSuchInstanceError as e: print('Error:- {}'.format(e)) finally: tLagOperationEntry = namedtuple('tLagOperationEntry','LagIfIndex LagConfigLastChange LagLACPPrimaryPort') LagOperationEntry_inters = [tLagOperationEntry(*uple) for uple in zip(*[tLagIfIndex,tLagConfigLastChange,tLagLACPPrimaryPort])] for OperationEntry in LagOperationEntry_inters: tLagOperationEntry = {} tLagOperationEntry['host'] = host tLagOperationEntry['interface_index'] = OperationEntry.LagIfIndex.value tLagOperationEntry['LagConfigLastChange'] = OperationEntry.LagConfigLastChange.value tLagOperationEntry['LagLACPPrimaryPort'] = OperationEntry.LagLACPPrimaryPort.value tLagOperationEntry_list.append(tLags) for data in tLagOperationEntry_list: print(data['host'],data['interface_index'],data['LagConfigLastChange'],data['LagLACPPrimaryPort'])this code showing blank output, however I am able to print individual lists.
RE: namedtuple help - Larz60+ - Oct-18-2019 There is no other output from your script except lines 27 and 28, unless the except clauses get executed. RE: namedtuple help - anna - Oct-18-2019 thanks Larz60+ one oid's output is not as per expectation, working on this. RE: namedtuple help - buran - Oct-18-2019 and what is the purpose to create list of namedtuples and immediately to create a list of dicts? RE: namedtuple help - anna - Oct-19-2019 Hi Buran, is there another way? I am following below post, assigning value to variable before print. https://python-forum.io/Thread-how-to-combine-mumtiple-for-loops-in-single-loop?pid=41095#pid41095 regards Anna RE: namedtuple help - buran - Oct-19-2019 (Oct-19-2019, 04:51 AM)anna Wrote: is there another way? I am following below post, assigning value to variable before print.well, exactly what I mean - use directly the namedtuple in the print, without converting to dict |