Skip to content

Instantly share code, notes, and snippets.

Created February 26, 2019 16:11
What would you like to do?
Read an Access Database using Python with the pyodbc module.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
Read an Access Database using pyodbc
Version: 1.0
Python 3.7
Date created: 24.02.2019
import pyodbc
conn_str = (
r'DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};'
# Connect to database
connection = pyodbc.connect(conn_str)
# 'Open' database
cursor = connection.cursor()
# Show tables
for table_info in cursor.tables(tableType='TABLE'):
# Fetch the data (from the 'Projekte' table)
cursor.execute('SELECT * FROM %s' % ('Projekte'))
db_data = cursor.fetchall()
# Show the fetched data
for row in db_data:
print (row)
# Close the connection
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment