module for working with the result set

john fabiani jfabiani at yolo.com
Mon May 17 13:09:55 EDT 2004


Diez B. Roggisch wrote:
> john fabiani wrote:
> 
> 
>>Hi,
>>newbie question:
>>PyPgSQL (postgres driver) returns a list (not a tuple O'Rielly states
>>DBAPI returns a tuple) and most of the books describe how to work with
>>tuples and dictionaries when working with a result set. Does anyone know
>>of a paper or tutorial that explains a few ways to deal with result
>>sets. Or if anyone knows of a module that will help (that I can study) -
>>that would be just as helpful?
> 
> 
> What exactly is your problem? Lists behave equally with respect to read
> accees to tuples. So whatever you want to do with a tuple, do it. 

That's what I thought but everytime I attempt to use any of the examples 
in the O'Reilly books I get errors.  I'm so new to this stuff I can't 
tell if it's me or the fact I not using tuples.  Things like the following:

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.

So I'm confused.  Also, using things like the dtuple module does not 
work at all.

thanks
John



More information about the Python-list mailing list