How to read one single line of csv data in Python?

后端 未结 7 1361
终归单人心
终归单人心 2020-11-28 05:04

There is a lot of examples of reading csv data using python, like this one:

import csv
with open(\'some.csv\', newline=\'\') as f:
  reader = csv.reader(f)
          


        
7条回答
  •  情歌与酒
    2020-11-28 05:32

    Just for reference, a for loop can be used after getting the first row to get the rest of the file:

    with open('file.csv', newline='') as f:
        reader = csv.reader(f)
        row1 = next(reader)  # gets the first line
        for row in reader:
            print(row)       # prints rows 2 and onward
    

提交回复
热议问题