csv 產生的數據都是字符串類型的,它不會做任何其他類型的轉換。如果需要做這樣的類型轉換,必須自己手動去實現
import csv,re from collections import namedtuple col_types=[str,float,str,str,str,int] with open(r'C:\Temp\ff.csv') as f: f_csv=csv.reader(f) headers=next(f_csv) print(headers) Row=namedtuple('Row',headers) for r in f_csv: row=Row(*r) print(row) print(type(row.IssueType)) row=tuple(convert(value) for convert,value in zip(col_types,row)) print(row)