-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtry and except
More file actions
36 lines (33 loc) · 875 Bytes
/
try and except
File metadata and controls
36 lines (33 loc) · 875 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# Figure out which line of the program below
#
#
# fhand = open('mbox-short.txt')
# count = 0
# for line in fhand:
# words = line.split()
# # print('Debug:', words)
# if len(words) == 0 : continue
# if words[0] != 'From' : continue
# print(words[2])
#
#
# is still not
# properly guarded. See if you can construct a text file which causes the
# program to fail and then modify the program so that the line is properly
# guarded and test it to make sure it handles your new text file.
file = input('Enter file name: ')
try :
fhand = open(file)
except:
print('File name not found. Please enter a new file name')
quit()
count = 0
for line in fhand:
words = line.split()
# print('Debug:', words)
if len(words) == 0:
continue
if words[0] != 'From':
continue
# print(words)
print(words[2])