Getting column names from a cursor using ODBC module?

M.-A. Lemburg mal at
Fri Jun 27 12:38:05 CEST 2008

John Machin wrote:
> On Jun 21, 11:58 pm, dana... at wrote:
>> Is there any way to retrieve column names from a cursor using the ODBC
>> module? Or must I, in advance, create a dictionary of column position
>> and column names for a particular table before I can access column
>> values by column names? I'd prefer sticking with the ODBC module for
>> now because it comes standard in Python.
>> I'm using Python 2.4 at the moment.
> Do you mean the odbc module? If so, it doesn't come standard in
> Python; it's part of the win32 package.
> I haven't used it for years -- my preference on Windows these days
> would be mxODBC if the client would pay the licence fee, otherwise
> pyodbc. Sorry I'm not answering your question ... perhaps you should
> be asking a different question :)

mxODBC comes with a cursor.columns() method which allows you to
query column names and many other column specific details of the

See the documentation for details:

If you just want to access the result set columns by name,
you can use the cursor.description tuple to map names to

Please also see the FAQ of the DB API spec reagrding the issues
involved with this approach:

Marc-Andre Lemburg

Professional Python Services directly from the Source
>>> Python/Zope Consulting and Support ...
>>> mxODBC.Zope.Database.Adapter ...   
>>> mxODBC, mxDateTime, mxTextTools ...
2008-07-07: EuroPython 2008, Vilnius, Lithuania

:::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,MacOSX for free ! :::: Software, Skills and Services GmbH  Pastor-Loeh-Str.48
    D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
           Registered at Amtsgericht Duesseldorf: HRB 46611

More information about the Python-list mailing list