Python Forum
how to combine mumtiple for loops in single loop
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to combine mumtiple for loops in single loop
#4
I only mean this
from easysnmp import Session
import time
start = time.time()
host = '10.10.10.1'

session = Session(hostname=host, community='xxxxxx', version=2)
intnames, intOpes, intAdms = (list(session.walk('1.3.6.1.2.1.2.2.1.' + c)) for c in '278')
 
for i in range(len(intnames)):
    print '{} {} {} {}'.format(host,intnames[i].value,intOpes[i].value,intAdm[i].value)
print('It took', time.time()-start, 'seconds.')
Your error has to do with the session.walk() call. Are you sure the remote host is reachable?

About the list index error, do you know if the three lists have equal length ?
Reply


Messages In This Thread
RE: how to combine mumtiple for loops in single loop - by Gribouillis - Mar-01-2018, 12:41 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Nested for loops - help with iterating a variable outside of the main loop dm222 4 1,743 Aug-17-2022, 10:17 PM
Last Post: deanhystad
  Print output in single file using pramika loop deepakkhw 1 2,154 Jul-11-2020, 11:57 AM
Last Post: j.crater
  Unable to combine print statements in for loop adeana 2 2,080 Jun-12-2020, 05:08 PM
Last Post: adeana
  Is it possible to avoid 2 loops inside another loop? SvetlanaofVodianova 2 2,242 Nov-27-2019, 02:30 PM
Last Post: Gribouillis
  Loop through folder of Excel Files and extract single column fioranosnake 2 4,632 Oct-28-2019, 05:19 PM
Last Post: fioranosnake
  Combine two scripts and loop BMC 2 2,122 Feb-17-2019, 02:13 PM
Last Post: BMC
  Loops - new terminal output to file for each loop jm_ice 1 2,649 Dec-21-2018, 02:42 PM
Last Post: ichabod801
  Python-for loop print into single line dragan979 4 7,166 Nov-23-2018, 01:01 AM
Last Post: wavic
  Using nested for loop with a single list mikeavison 3 3,381 Aug-12-2017, 08:13 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020