<p>我有一个典型的<code>list</code>数据,其中第一个项是一个datetime对象,下面的项是与日期和时间相对应的数据。我想打印并格式化<code>datetime</code>对象。{{I希望{cd2>的表示形式{cd2>更倾向于{cd5}。在</p>
<p>我试过了</p>
<pre><code> print('{}'.format(', '.join(map(str,row))))
</code></pre>
<p>它工作正常,但我真的不想要那种格式(从<a href="https://stackoverflow.com/questions/9052433/overriding-default-format-when-printing-a-list-of-datetime-objects">overriding default format when printing a list of datetime objects</a>)。在</p>
<p>我知道如何使用<code>strftime</code>,但我不知道如何对<code>list</code>中的数据调用它。似乎应该有一个简单的方法来做到这一点。{cda{1>中的搜索结果都是{cda}无法完成的。在</p>
<pre><code>print ", ".join((row[0].strftime('%Y%m%d'),)+tuple(str(i) for i in row[1:]))
</code></pre>
<p>在下面的例子中,我将这一行定义为<code>def print_row(row):</code>。在</p>
^{pr2}$