Python import csv to list

后端 未结 13 1253
后悔当初
后悔当初 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
    

提交回复
热议问题