Skip to content

Commit 5bb8a9e

Browse files
authored
Create Assignment_8_5.py
1 parent 96c57f6 commit 5bb8a9e

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

Assignment_8_5.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
'''Open the file mbox-short.txt & read it line by line.
2+
When you find a line that starts with From like the following line:
3+
From stephen.marquard@uct.ac.za Sat Jan 5 09:14:16 2008
4+
You will parse the From line using split() & print out the second word in the line (entire address).
5+
Then print out a count and end.
6+
FILE: mbox-short.txt
7+
WEB LINK: http://www.py4e.com/code3/mbox-short.txt'''
8+
9+
name = input('Enter the file name: ')
10+
file = open(name)
11+
word = []
12+
count = 0
13+
for line in file:
14+
line = line.rstrip()
15+
if line.startswith('From'):
16+
count += 1
17+
word = line.split()
18+
print(word[1])
19+
20+
print('There were',count,'lines in the file with From as the first word')

0 commit comments

Comments
 (0)