csv
import csv
from collections import namedtuple
def csv_read()
with open('product.csv',encoding = 'utf8') as f:
reader = csv.reader(f)
headers = next(reader)
print(headers)
for row in reader:
print('编号{}\t产品{}\t单价{}'.format(row[0],row[1],row[3]))
def csv_read_by_namedtuple():
with open('product.csv', encoding = 'utf8') as f:
reader = csv.reader(f)
headers = next(reader)
Row = namedtuple('Row', headers)
for r in reader:
row = Row (*r)
print(row)
for row in reader:
print(row)
def csv_read_by_dict():
with open('product.csv',encoding = 'utf8') as f:
reader = csv.DictReader(f)
if __name__ =='__main__':
csv_read()