MS Access db (mdb): viewing table attributes

gau.tai at gmail.com gau.tai at gmail.com
Fri Mar 10 12:53:21 EST 2006


I have an Access 2003 database, protected by a workgroup, that I am
trying to view through python.  Currently, I'm attempting dao with the
win32 package, and I'm able to view all of the table names, but I don't
know how to view the attributes of the tables.

My code:

import win32com.client
from pprint import pprint

#sample code to list all tables in the selected database
daoEngine = win32com.client.Dispatch('DAO.DBEngine.36')
dtbs = daoEngine.OpenDatabase('database_file.mdb')
for table in dtbs.TableDefs:
    if table.Name[:4] <> "MSys" and table.Name[:4] <> "~TMP":
        pprint(table.Name.encode('utf-8'))
        #the above works, but below does not:
        for col in table.Fields:
             pprint(col.Name, Col.Type, Col.Size)

I am getting that len(Fields) = 0, and I know the database tables are
all full of columns (and data).  Is there also some resource that
defines all the properties of TableDefs?  I wasn't able to find a
python reference for this.

Thank You,
Gau




More information about the Python-list mailing list