Python ODBC Datenbankzugriff mit den Win32 extensions

Thomas Darimont

Erfahrenes Mitglied
Hallo!

Um von Python aus per ODBC auf Datenbanken zugreiffen zu können kann man sich beispielsweise der Win32 Extensions für Python bedienen:
http://starship.python.net/crew/mhammond/win32/

Hier mal ein Beispiel für den Zugriff auf eine MS Access Datenbank
Code:
import dbi, odbc
 try:
 		s = odbc.odbc('DRIVER={Microsoft Access Driver (*.mdb)};DBQ=C:\Programme\Microsoft Office\Office\Samples\Nordwind.mdb')
 		cur = s.cursor()
 		cur.execute('select * from kunden')
 		print cur.description
 		for tup in cur.description:
 				print tup[0],
 		print
 		while 1:
 				rec = cur.fetchmany(10)
 				if not rec: break
 				print rec
 except NameError,e:
 		print 'error ', e, 'undefined'

Gruß Tom
 
Zurück