Python Database Connectivity

Martijn Faassen m.faassen at vet.uu.nl
Wed Jan 5 09:06:28 EST 2000


Timothy Grant <tjg at avalongroup.net> wrote:
> Hi,

> Just wondering if anyone has used Python on Windows to connect to an
> ODBC database?

The PythonWin extensions contain an ODBC package that conforms (last
I checked) to the Python DB spec version 1. So if you have installed
those you can use ODBC; a basic example:

import odbc, dbi

db = odbc.odbc("databasename")
cur = db.cursor()
sql = "select * from foo"
cur.execute(sql)
data = cur.fetchall()
print data
cur.close()
db.close()

I imagine mxODBC works much like that too (though it may implement the DB
spec version 2?).

Regards,

Martijn
-- 
History of the 20th Century: WW1, WW2, WW3?
No, WWW -- Could we be going in the right direction?



More information about the Python-list mailing list