This simple code shows ODBC data sources. It uses odbc
module.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | #!/usr/bin/env python
# -*- coding: utf8 -*-
__version__ = '$Id: odbc_sources.py 1696 2013-12-10 11:03:08Z mn $'
# shows ODBC data sources with driver info
# author: Michal Niklas
import odbc
def show_odbc_sources():
sl = []
source = odbc.SQLDataSources(odbc.SQL_FETCH_FIRST)
while source:
dsn, driver = source
sl.append('%s [%s]' % (dsn, driver))
source = odbc.SQLDataSources(odbc.SQL_FETCH_NEXT)
sl.sort()
print('\n'.join(sl))
if __name__ == '__main__':
show_odbc_sources()
|
Which ODBC module are you using? I don't see one in the standard library, and several are available at https://wiki.python.org/moin/ODBC
odbc
module is a part of ActiveState distribution (tested with 2.7 and 3.3). I believe it is also in PyWin32 package.I have made similar recipe using
pyodbc
module: http://code.activestate.com/recipes/578815-printing-list-of-odbc-data-sources-with-pyodbc-mod/