Python-100-Days/Day01-15/code/Day11/csv1.py

22 lines
363 B
Python
Raw Normal View History

2018-04-27 00:00:22 +08:00
"""
读取CSV文件
Version: 0.1
Author: 骆昊
Date: 2018-03-13
"""
import csv
filename = 'example.csv'
try:
2019-05-03 21:17:36 +08:00
with open(filename) as f:
reader = csv.reader(f)
data = list(reader)
2018-04-27 00:00:22 +08:00
except FileNotFoundError:
2019-05-03 21:17:36 +08:00
print('无法打开文件:', filename)
2018-04-27 00:00:22 +08:00
else:
2019-05-03 21:17:36 +08:00
for item in data:
print('%-30s%-20s%-10s' % (item[0], item[1], item[2]))