用于 Python 的 MS Access 库 [英] MS Access library for python
本文介绍了用于 Python 的 MS Access 库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有在python中使用MS Access数据库的库?win32 模块不像 MySQL 库那么简单.有没有更简单的方法在 Python 中使用 MS Access?
解决方案
取决于你想做什么,pyodbc 可能正是您要找的.p>
import pyodbcdef mdb_connect(db_file, user='admin', password = '', old_driver=False):driver_ver = '*.mdb'如果不是 old_driver:driver_ver += ', *.accdb'odbc_conn_str = ('DRIVER={Microsoft Access Driver (%s)}'';DBQ=%s;UID=%s;PWD=%s' %(driver_ver, db_file, 用户, 密码))返回 pyodbc.connect(odbc_conn_str)conn = mdb_connect(r'''C:x.mdb''') # 只有绝对路径!
<块引用>
注意:您可以下载可免费再分发的 新驱动程序,如果您没有安装 MSOffice.
Is there a library for using MS Access database in python? The win32 module is not as easy as the MySQL library. Is there a simpler way to use MS Access with Python?
解决方案
Depending on what you want to do, pyodbc might be what you are looking for.
import pyodbc
def mdb_connect(db_file, user='admin', password = '', old_driver=False):
driver_ver = '*.mdb'
if not old_driver:
driver_ver += ', *.accdb'
odbc_conn_str = ('DRIVER={Microsoft Access Driver (%s)}'
';DBQ=%s;UID=%s;PWD=%s' %
(driver_ver, db_file, user, password))
return pyodbc.connect(odbc_conn_str)
conn = mdb_connect(r'''C:x.mdb''') # only absolute paths!
Note: you may download the freely-redistributable new-driver, if you don't have MSOffice installed.
这篇关于用于 Python 的 MS Access 库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文