PEP 284, Integer for-loops

James_Althoff at i2.com James_Althoff at i2.com
Mon Mar 11 19:15:43 EST 2002


[Philip Hunt]
> 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...

Assuming that I want to share and reuse this amongst the development team I
don't think I see that

    import tableutils
    for rowindex in tableutils.rowKeys(table):

or

    from tableutils import rowKeys
    for rowindex in rowKeys(table):

is *less* cumbersome than

    for rowindex in table.getRowCount():

But I can see why you might prefer using a helper function -- especially if
you don't want to type "getRowCount" a lot, if that's what you mean.

Thanks for your suggestion.

Jim





More information about the Python-list mailing list