使用python获取Windows 7中可用的odbc驱动程序列表 [英] Getting list of odbc drivers available in windows 7 using python
问题描述
我正在尝试用 python 编写一个通用的数据库连接器类.为此,我想首先检查机器上安装了哪些驱动程序,如果机器中缺少所需的驱动程序,则抛出错误.
I am trying to write a generic database connector class in python. For this I want to first check what drivers are installed on the machine and throw an error if the required drivers are missing in the machine.
有没有办法在python中做到这一点?
Is there a way to do this in python?
推荐答案
我意识到这是一个迟到的回复......但我自己偶然发现了答案;以防其他人正在寻找答案.
I realise this is a late reply ... but just stumbled across the answer myself; in case anyone else is looking for an answer.
pyodbc
有一个返回已安装 ODBC 驱动程序列表的方法.当然,这只是驱动程序名称的列表,因此获取最新驱动程序有点繁琐,但希望这会有所帮助.
pyodbc
has a method which returns a list of installed ODBC drivers. Granted, it's just a list of the driver names, so it's a bit fiddly getting to the most current driver, but hopefully this will help.
我使用正则表达式(通过内置的 re
模块)过滤到我需要的驱动程序.
I use regex (via the built-in re
module) to filter down to the driver I need.
import pyodbc
pyodbc.drivers()
输出提供已安装的 ODBC 驱动程序列表.
The output provides a list of installed ODBC drivers.
这篇关于使用python获取Windows 7中可用的odbc驱动程序列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!