module for working with the result set
Diez B. Roggisch
deetsNOSPAM at web.de
Mon May 17 20:37:49 EDT 2004
john fabiani wrote:
> See this does not make sense to me.
>
>
> mydata[0]
> ['5992 ', 'A', '5346 ', ' ', 'XX
> ', 'Kathy Stromme ', 'RICHMOND AMERICAN HOMES
> ', '7250 WEST PEAK, ST # 212 ', '
<snip>
well - its a list, and I bet its a list of columns. The columns are mostly
strings (at least at the beginning) and obviously are space padded to match
up to their size.
The code you posted earlier assumes that the result row is returned as dict,
thus iterating over the row yields in the keys. Consider this example:
d = {"key1" : 10, "key2" : 20 }
for key in d:
print key, d[key]
that results in
key1
10
key2
20
notice how putting a dict as sequence in a for ... in ... : statement
iterates the keys.
Now you don't get a dict, but a list of row-values. So your code
for field in mydata[0]:
print mydata[0][field]
iterates over the data you presented, yielding the '5992 '
as first value. Thats all. Of course using that value as index makes no
sense.
To summarize: you expect data to be returned as dict per row, where the data
is returned as list.
Use the cursors .description property to get a mapping between name and
index.
--
Regards,
Diez B. Roggisch
More information about the Python-list
mailing list