As further example of how to use the results of runQuery, here are seven different ways to print out the table, and their results follow. Note that some of the later methods exercise some more advanced Jython concepts such as list comprehensions and string formatting, but their intent should be obvious. Generally speaking, the more concise Jython code becomes, the more readable it is.
table = system.db.runQuery("SELECT * FROM Test")
print "Printing TEST Method 1..."
for row in table:
for col in row:
print col,
print ""
print ""
print "Printing TEST Method 2..."
for row in table:
print row[0], row[1]
print ""
print "Printing TEST Method 3..."
for row in table:
print row["ID"], row["VALUE"]
print ""
print "Printing TEST Method 4..."
for rowIdx in range(len(table)):
print "Row ",str(rowIdx)+": ", table[rowIdx][0], table[rowIdx][1]
print ""
print "Printing TEST Method 5..."
print [str(row[0])+", "+ str(row[1]) for row in table]
print ""
print "Printing TEST Method 6..."
print ["%s, %s" % (row["ID"],row["VALUE"]) for row in table]
print ""
print "Printing TEST Method 7..."
print [[col for col in row] for row in table]
print ""
The result would be:
Printing TEST Method 1...
0 3.55
1 67.2
2 9.87
Printing TEST Method 2...
0 3.55
1 67.2
2 9.87
Printing TEST Method 3...
0 3.55
1 67.2
2 9.87
Printing TEST Method 4...
Row 0: 0 3.55
Row 1: 1 67.2
Row 2: 2 9.87
Printing TEST Method 5...
['0, 3.55', '1, 67.2', '2, 9.87']
Printing TEST Method 6...
['0, 3.55', '1, 67.2', '2, 9.87']
Printing TEST Method 7...
[[0, 3.55], [1, 67.2], [2, 9.87]]