[TriPython] mutliple iterations in python

Will Spearman willspearman at gmail.com
Thu Aug 4 11:25:34 EDT 2016


They're using collections.MutableSequence for the rows, which is an
iterator, but they must have broken iteration in their TypedList subclass.
I don't see any obvious error in their implementation. Michael's suggestion
should work as a workaround.

On Thu, Aug 4, 2016 at 11:10 AM Beth Singley <beth.singley at gmail.com> wrote:

>    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
> _______________________________________________
> TriZPUG mailing list
> TriZPUG at python.org
> https://mail.python.org/mailman/listinfo/trizpug
> http://tripython.org is the Triangle Python Users Group
-------------- next part --------------
   They're using collections.MutableSequence for the rows, which is an
   iterator, but they must have broken iteration in their TypedList subclass.
   I don't see any obvious error in their implementation. Michael's
   suggestion should work as a workaround.
   On Thu, Aug 4, 2016 at 11:10 AM Beth Singley <[1]beth.singley at gmail.com>
   wrote:

        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][2]beth.singley at gmail.com

     References

        Visible links
        1. mailto:[3]beth.singley at gmail.com
     _______________________________________________
     TriZPUG mailing list
     [4]TriZPUG at python.org
     [5]https://mail.python.org/mailman/listinfo/trizpug
     [6]http://tripython.org is the Triangle Python Users Group

References

   Visible links
   1. mailto:beth.singley at gmail.com
   2. mailto:beth.singley at gmail.com
   3. mailto:beth.singley at gmail.com
   4. mailto:TriZPUG at python.org
   5. https://mail.python.org/mailman/listinfo/trizpug
   6. http://tripython.org/


More information about the TriZPUG mailing list