Last active
October 27, 2020 16:10
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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