How to print all columns in SQLAlchemy ORM

后端 未结 10 1968
再見小時候
再見小時候 2020-12-28 15:18

Using SQLAlchemy, I am trying to print out all of the attributes of each model that I have in a manner similar to:

SELECT * from table;

How

10条回答
  •  孤城傲影
    2020-12-28 15:35

    I believe this is the easiest way:

    print [cname for cname in m.__dict__.keys()]
    

    EDIT: The answer above me using sqlalchemy.inspection.inspect() seems to be a better solution.

提交回复
热议问题