module for working with the result set

Diez B. Roggisch deetsNOSPAM at web.de
Mon May 17 14:04:58 EDT 2004


> mydata=cursor.fetchmany(10)
> for field in mydata[0]:
>    print mydata[0][field]
> 
> Traceback (most recent call last):
>    File "C:\Python23\Lib\site-packages\sm\scriptutils.py", line 49, in run
>      exec codeObject in mainDict
>    File "<source>", line 10, in ?
>    File "C:\Python23\Lib\site-packages\pyPgSQL\PgSQL.py", line 2063, in
> __getitem__
>      key = self._xlatkey[key.lower()]
> KeyError: '5992      '
> Exception raised while running script  <source>
> 
> But ;(
> print mydata[0][0], mydata[0][1]
> the above works perfectly - prints what I want.

it seems that the value of field is 5992, and that isn't a key to the row -
which is quite likely, as 5992 as column-name is most probably forbidden,
and as index a little bit high - can't imagine what a table with ~6000
columns should hold....

Now what about showing us the result of this:

mydata=cursor.fetchmany(10) 
print mydata[0]

Then one can tell how to access  the fields. Thats a general advice: when
such things occur, print out the values in question short before the
problem, then you can see if and more important why what you expect and
what you get differ.

-- 
Regards,

Diez B. Roggisch



More information about the Python-list mailing list