[TriPython] mutliple iterations in python
Beth Singley
beth.singley at gmail.com
Thu Aug 4 11:10:24 EDT 2016
Hello group,
Here's a python question I'm hoping someone can explain. (I'm headed to
stackoverflow next)
I'm writing a couple of scripts to automate some common tasks our users are
doing in Smartsheets (an online Excel 'equivalent'). I often need to
iterate through the rows on the sheet, which are housed as a list of rows
on the sheet object.
However, when I want to run through the same sheet a second time in the
same script, I find that the second loop won't work unless I create a brand
new variable to hold a new instance of the same sheet. (Code snippet
below). It's as if the pointer is stuck at the bottom row after the first
loop. My solution seems awkward to me, adding an extra call and slowing
down the whole script. Am I missing something? How do I start over at the
top of the sheet's rows?
Code snippet -
sheet1= smartsheet.Sheets.get_sheet(sid)
for row in sheet1.rows:
# collect information from each row for some other purpose
#transform information collected...
for row in sheet1.rows:
print(row.cells[0].value) <-- this will not print anything out unless I
create a whole new sheet object
#do something else to the rows based on information gathered and
transformed between loops.
Any guidance appreciated!
All the best,
Beth
beth.singley at gmail.com
-------------- next part --------------
Hello group,
Here's a python question I'm hoping someone can explain. (I'm headed to
stackoverflow next)
I'm writing a couple of scripts to automate some common tasks our users
are doing in Smartsheets (an online Excel 'equivalent'). I often need to
iterate through the rows on the sheet, which are housed as a list of rows
on the sheet object.
However, when I want to run through the same sheet a second time in the
same script, I find that the second loop won't work unless I create a
brand new variable to hold a new instance of the same sheet. (Code snippet
below). It's as if the pointer is stuck at the bottom row after the first
loop. My solution seems awkward to me, adding an extra call and slowing
down the whole script. Am I missing something? How do I start over at the
top of the sheet's rows?
Code snippet -
sheet1= smartsheet.Sheets.get_sheet(sid)
for row in sheet1.rows:
# collect information from each row for some other purpose
#transform information collected...
for row in sheet1.rows:
print(row.cells[0].value) <-- this will not print anything out unless
I create a whole new sheet object
#do something else to the rows based on information gathered and
transformed between loops.
Any guidance appreciated!
All the best,
Beth
[1]beth.singley at gmail.com
References
Visible links
1. mailto:beth.singley at gmail.com
More information about the TriZPUG
mailing list