get table columns from sqlAlchemy table model

后端 未结 1 1365
一个人的身影
一个人的身影 2021-01-03 22:04

I have a table where I would like to fetch all the column names however after browsing the interwebs I could not find a way that works. This is what my table looks like:

相关标签:
1条回答
  • 2021-01-03 22:32

    You get all of the columns from __table__.columns:

    myTable.__table__.columns
    

    or

    myTable.__table__.c
    

    The columns would be in format myTable.col1 (table name is included). If you want just column names, get the .key for each column:

    [column.key for column in myTable.__table__.columns]
    
    0 讨论(0)
提交回复
热议问题