擅长:python、mysql、java
<p>要只读取csv文件的第一行,请对reader对象使用<a href="https://docs.python.org/3/library/functions.html#next">^{<cd1>}</a>。</p>
<pre><code>with open('some.csv', newline='') as f:
reader = csv.reader(f)
row1 = next(reader) # gets the first line
# now do something here
# if first row is the header, then you can do one more next() to get the next row:
# row2 = next(f)
</code></pre>
<p>或:</p>
<pre><code>with open('some.csv', newline='') as f:
reader = csv.reader(f)
for row in reader:
# do something here with `row`
break
</code></pre>