Getting list of odbc drivers available in windows 7 using python

醉酒当歌 提交于 2020-01-12 18:50:55

问题


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.

Is there a way to do this in python?


回答1:


I realise this is a late reply ... but just stumbled across the answer myself; in case anyone else is looking for an answer.

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.

I use regex (via the built-in re module) to filter down to the driver I need.

import pyodbc
pyodbc.drivers()

The output provides a list of installed ODBC drivers.




回答2:


There's nothing built into Python that will allow you to do this, except maybe doing something really ugly with ctypes and I'm not sure if that will work. However, you can probably do it with Tim Golden's wmi.py module.

  • https://pypi.python.org/pypi/WMI/

I've found examples of using WMI to find regular drivers:

  • WMI call to get drivers

So you would probably have to filter the list somehow.



来源:https://stackoverflow.com/questions/26712379/getting-list-of-odbc-drivers-available-in-windows-7-using-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!