Python import csv to list

后端 未结 13 1096
后悔当初
后悔当初 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 07:01

    A simple loop would suffice:

    lines = []
    with open('test.txt', 'r') as f:
        for line in f.readlines():
            l,name = line.strip().split(',')
            lines.append((l,name))
    
    print lines
    
    0 讨论(0)
提交回复
热议问题