Skip to content

Instantly share code, notes, and snippets.

@folksilva
Last active October 27, 2020 16:10
Show Gist options
  • Save folksilva/7646239 to your computer and use it in GitHub Desktop.
Save folksilva/7646239 to your computer and use it in GitHub Desktop.
Exemplo de conexão do Python com um banco de dados MS Access via ODBC Necessário ter: - Python 2.7 - http://www.python.org/download/ - pyodbc 3 - https://code.google.com/p/pyodbc
"""
Exemplo de conexão do Python com um banco de dados MS Access via ODBC
Necessário ter:
- Python 2.7 - http://www.python.org/download/
- pyodbc 3 - https://code.google.com/p/pyodbc
Sugestão de editor: JetBrains PyCharm Community Edition (http://www.jetbrains.com/pycharm/)
"""
# -*- coding:utf-8 -*-
__author__ = 'Luiz Fernando da Silva <[email protected]>'
import pyodbc
dbpath = "c:\\caminho\\para\\arquivo\\Access2003.mdb"
driver = "{Microsoft Access Driver (*.mdb, *.accdb)}"
conn = pyodbc.connect("DRIVER={};DBQ={}".format(driver, dbpath))
cursor = conn.cursor()
cursor.execute("SELECT * FROM Tabela")
for row in cursor:
print row.nome, row.valor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment