擅长:python、mysql、java
<p>你从未增加你的<code>i</code>。要么这样做,要么把它留给<code>enumerate</code>。另外,如果您澄清只想打印4行,最好在循环的顶部进行检查,否则您将打印5行:</p>
<pre><code>lastweek1 = list()
for i, row in enumerate(rows):
if i == 4:
break
lastweek1.append(row)
</code></pre>
<p>或者你不能把它复杂化:)。前四整行就这么简单</p>
<pre><code>lastweek1 = rows[:4]
</code></pre>
<p>或者如果它是一个发电机(很可能),你需要具体化它</p>
<pre><code>lastweek1 = list(rows[:4])
</code></pre>