增加了main函数

pull/423/head
Zpadger 2020-01-07 10:10:39 +08:00 committed by GitHub
parent d77e71c167
commit 78590df968
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()