Wanted : boiler plate example of using python to query a database

Harry George hgg9140 at cola2.ca.boeing.com
Thu Dec 19 13:22:53 EST 2002


stevesusenet at yahoo.com (Steve) writes:

> Hi;
> 
> I haven't found this yet in something online ( I have "Learning
> Python" coming to me in the mail ).
> 
> Can anyone point me to a basic, basic boiler plate example of using
> python to query a single table in a database?
> 
> Thanks in advance
> 
> Steve

python2.2
>>> import os,sys
>>> from pyPgSQL import libpq
>>> from pyPgSQL import PgSQL
>>> db=PgSQL.connect(database='testdb')
>>> c=db.cursor()
>>> c.execute("select * from pg_class")
>>> results=c.fetchall()
>>> print results

However, this doesn't begin to address how to do it cleanly in a real
app.  Take a look at PyDOS from Zope as a possible way to tackle that.

-- 
harry.g.george at boeing.com
6-6M31 Knowledge Management
Phone: (425) 294-8757



More information about the Python-list mailing list