python - How to advance iteration while inside an iterator spreadsheet rows -


i need advance iteration of rows read , excel spreadsheet while still inside iterator loop.

try:     r in range(insheet.nrows):         cdat = insheet.cell(r, 0).value         if not cdat == xlrd.empty_cell.value:             if hasnumbers(cdat):                 #strip digits client pneumonic                 #pdb.set_trace()                 if re.sub(r'\d','',cdat) == clntid:                     #pdb.set_trace()                     #this call belongs client                     memid = cdat                     fincallblock = true                     while fincallblock:                         #output line formatted callheader                         #inc row counter     can't ==>   next(r)                         cdat = cdat.strip(insheet.cell(r, 0).value)                          if cdat == u"call resolved":                             pdb.set_trace()                             fincallblock = false 

the code crashes marked with:

-> next(r) (pdb++) n typeerror: 'int object not iterator' 

and cannot find out how it.

you can assign range variable , advance it

myrange = iter(range(insheet.rows))  r in myrange:      ...     next(myrange) 

of course range works way in python 3. if still under python 2 xrange

beware r value not change unless not advance iterator assign ouput of r:

r = next(myrange) 

you should cath potential stopiteration exception may raised when advancing range


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -