欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

从CSV文件导入数据

程序员文章站 2024-02-10 22:16:16
...
import csv

filename = 'D:\CSV\AssetsImportCompleteSample.csv'

data=[]

try:
    with open(filename) as f:
        reader = csv.reader(f)
        header = next(reader)
        data=[row for row in reader]
except csv.Error as e:
    print("Error reading CSV file at line:%s,%s",reader.line_num,e)
    sys.exit(-1)
    
if header:
    print(header)
    print('========================')
for datarow in data:
    print(datarow)