with open('a.txt', 'r') as f:
badLine = 0
goodLine = 0
totalLine = 0
for line in f:
try:
d1, d2, d3 = line.split()
except:
badLine += 1
else:
goodLine += 1
finally:
totalLine += 1
print('totalLine : {}, badLine: {}, goodLine: {}'.format(str(totalLine), str(badLine), str(goodLine)))
以下是 a.txt的內容:
1 2 3
yy
5 6 7
xx
6 7 8
輸出:
totalLine : 5, badLine: 2, goodLine: 3
<Note>
raise Exception("自己raise exception")
raise Exception("自己raise exception")
沒有留言:
張貼留言