增加了main函数
parent
07bb5ab8b9
commit
364168fe3f
|
@ -8,14 +8,20 @@ Date: 2018-03-13
|
|||
|
||||
import csv
|
||||
|
||||
filename = 'example.csv'
|
||||
def main():
|
||||
|
||||
try:
|
||||
# filename = 'example.csv' # 无法打开文件!: example.csv
|
||||
filename = 'teacher.csv'
|
||||
|
||||
try:
|
||||
with open(filename) as f:
|
||||
reader = csv.reader(f)
|
||||
data = list(reader)
|
||||
except FileNotFoundError:
|
||||
print('无法打开文件:', filename)
|
||||
else:
|
||||
except FileNotFoundError:
|
||||
print('无法打开文件!:',filename)
|
||||
else:
|
||||
for item in data:
|
||||
print('%-30s%-20s%-10s' % (item[0], item[1], item[2]))
|
||||
print('%-30s%-20s%-10s' % (item[0],item[1],item[2]))
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
Loading…
Reference in New Issue