PEP 284, Integer for-loops

phil hunt philh at comuno.freeserve.co.uk
Mon Mar 11 18:48:25 EST 2002


On Mon, 11 Mar 2002 11:31:16 -0800, James_Althoff at i2.com <James_Althoff at i2.com> wrote:
>
>One of your 3rd party components is a table.  It has a basic access
>protocol via methods like this:
>    def getRowCount(): pass
>    def getColumnCount(): pass
>    def getValueAt(rowIndex,columnIndex): pass
>    def setValueAt(rowIndex,columnIndex): pass
>
>[...]
>Perhaps you could give some ideas on approaches that would be more
>"Pythonic"?

How about:

def rowKeys(table):
   return xrange(0, table.getRowCount())

def someFunction():
   for r in rowKeys(someTable):
      #...iterate over all the rows in (someTable)

Note that this is less cumbersome than your chosen:

   for r in someTable.getRowCount():
      #...iterate...




-- 
<"><"><"> Philip Hunt <philh at comuno.freeserve.co.uk> <"><"><">
"I would guess that he really believes whatever is politically 
advantageous for him to believe." 
                        -- Alison Brooks, referring to Michael
                              Portillo, on soc.history.what-if



More information about the Python-list mailing list