Python import csv to list

后端 未结 13 1341
后悔当初
后悔当初 2020-11-22 06:15

I have a CSV file with about 2000 records.

Each record has a string, and a category to it:

This is the firs         


        
13条回答
  •  半阙折子戏
    2020-11-22 06:57

    Updated for Python 3:

    import csv
    
    with open('file.csv', newline='') as f:
        reader = csv.reader(f)
        your_list = list(reader)
    
    print(your_list)
    

    Output:

    [['This is the first line', 'Line1'], ['This is the second line', 'Line2'], ['This is the third line', 'Line3']]
    

提交回复
热议问题