PEP 284, Integer for-loops

James_Althoff at i2.com James_Althoff at i2.com
Mon Mar 11 14:31:16 EST 2002


[Tim Legant]
> So either Jason and I are significantly better than you and your
> team at expressing ourselves naturally in Python <wink> or it's
> the need to interface with Java that's forcing you to use integer
> indices all the time.  I'm betting big money on the latter.

I'm happy to believe you all are excellent programmers versed in Pythonic
ways.  And I'm always happy to learn something new.  So feel free to help
me on this one.

Here's your mission.  You are writing applications that deal with advanced
spreadsheets populated from database tables.  Your spreadsheets need to
have all the features of Excel including advanced things like pivot tables
for multi-dimensional OLAP analysis, reports, charts, graphs, etc.  The
data in your spreadsheets can be fairly complex and can include images.

Your market demands that you use Java.  C-Python is not an option.  You
will be using 3rd party components written in Java.  These component were
not created by the folks at PythonLabs.  These components do not follow any
of Python's standard protocols.  You do not have the source code to these
components.  Furthermore, due to the advanced nature of the application and
its data you understand that you are on the hairy edge of acceptability of
performance.  You have noted that creating Python subclasses of Java
superclasses can slow performance -- in your case, it drops below
acceptable levels.  Same with wrapper classes.  Also note that the version
of Jython used, 2.1, does not support iter/__iter__ and does not support
generators.

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

You have lots of example code written in Java that manipulates this
component via row and column indices using for-loops.

Your team will be writing hundreds of code fragments that do things like:
    - take a specified formula and apply it to a specified column for each
row
    - take a specified formula and apply it to a specified row for each
column
    - pivot the table on a specified column, spread the cells in that
column across a specified row
    - from a specified formula, calculate and set the value for every other
row in a given column
    - etc., etc., etc.  (think many hundreds of variations here)

We tend to use for-loops based on indices for this type of code.  We could
drop back to writing while-loops; but that seems more error-prone, like
more work, and less favorable to the programmers around here.

Perhaps you could give some ideas on approaches that would be more
"Pythonic"?

Thanks,

Jim Althoff
Senior Vice President
i2 Technologies, Inc.






More information about the Python-list mailing list