【问题标题】:How to fetch column names of a table to a list or tuple如何将表的列名获取到列表或元组
【发布时间】:2014-11-02 06:56:08
【问题描述】:

我在 ms-access db 中有一个表,我只需要将该表的列名提取到列表或元组中。

如果有人可以提出疑问或将我指向这方面的文档。

【问题讨论】:

    标签: python ms-access


    【解决方案1】:

    类似于问题here,你可以这样做:

    # -*- coding: utf-8 -*-
    import pypyodbc
    cnxn = pypyodbc.connect(
        r'Driver={Microsoft Access Driver (*.mdb, *.accdb)};' +
        r'DBQ=C:\Users\Public\Database1.accdb')
    crsr = cnxn.cursor()
    res = crsr.execute("SELECT * FROM Clients WHERE 1=0")
    columnList = [tuple[0] for tuple in res.description]
    crsr.close()
    cnxn.close()
    print(columnList)
    

    【讨论】:

      猜你喜欢
      • 2019-11-18
      • 2021-10-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-20
      相关资源
      最近更新 更多