增加了main函数

pull/333/head
Zpadger 2020-01-07 10:09:25 +08:00 committed by GitHub
parent 07bb5ab8b9
commit 364168fe3f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 10 deletions

View File

@ -8,14 +8,20 @@ Date: 2018-03-13
import csv
filename = 'example.csv'
def main():
try:
with open(filename) as f:
reader = csv.reader(f)
data = list(reader)
except FileNotFoundError:
print('无法打开文件:', filename)
else:
for item in data:
print('%-30s%-20s%-10s' % (item[0], item[1], item[2]))
# 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:
for item in data:
print('%-30s%-20s%-10s' % (item[0],item[1],item[2]))
if __name__ == '__main__':
main()