<p>我是Python的新手,我想知道是否有更好的解决方案来动态显示对象下的所有属性(关键字、woe\u代码、时间戳)。你知道吗</p>
<p>原始代码:</p>
<pre><code>trends = models.Trends.query.all()
for t in trends:
print t.keyword, t.woe_id, t.woe_code, t.timestamp #I know this is wrong, hardcoding the attributes.
</code></pre>
<p>新代码:</p>
<pre><code>trends = models.Trends.query.all()
for t in trends:
for k, v in vars(t).iteritems():
print k+"KEY"
print v+"Value"
</code></pre>