[DB-SIG] Again

Andy Todd andy47 at halfcooked.com
Wed Sep 10 10:35:14 EDT 2003


Eivind Tagseth wrote:

> * james at digconn.co.uk <james at digconn.co.uk> [030910 08:21]:
> 
>>can someone please tell me what i'm mean't to do when i get this message:
>><built-in method fetchall of cursor object at 0x015AF7A0>
>>My code leading up to this is:
>>
>>db = psycopg.connect('host=localhost dbname=dataname user=postgres')
>>cursor=db.cursor()
>>cursor.execute('SELECT * FROM "RingInfo"')
>>cursor.fetchall
> 
> 
> You're printing the method, no calling it.  Try cursor.fetchall()
> 
> 
> 
> Eivind
> 
> _______________________________________________
> DB-SIG maillist  -  DB-SIG at python.org
> http://mail.python.org/mailman/listinfo/db-sig

And whilst you are at it, assign the results of the call to something, 
otherwise you will lose them. A simple approach is;

 >>> cursor.execute('<my query>')
 >>> results=cursor.fetchall()
 >>> print "I have %d rows" % len(results)
 >>> for row in results:
 >>>     print row

Or just fetch a single row if you're simply testing, replace the call to 
'fetchall' with 'fetchone'. Regardless, you should experiment in the 
Python interpreter as its a very forgiving environment - and perhaps 
brush up on your Python knowledge with one of the excellent tutorials 
that are available on-line (http://www.python.org/topics/learn/).

Regards,
Andy
-- 
--------------------------------------------------------------------------------
 From the desk of Andrew J Todd esq - http://www.halfcooked.com/




More information about the DB-SIG mailing list