python的MS Access库 [英] MS Access library for python

查看:100
本文介绍了python的MS Access库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否存在用于在python中使用MS Access数据库的库? win32模块不像MySQL库那样简单.是否有更简单的方法将MS Access与Python结合使用?

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?

推荐答案

根据您要执行的操作, pyodbc 可能就是您想要的.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆