Skip to content

Commit 9e6ea73

Browse files
Create Assignment 8.5
1 parent ec1a354 commit 9e6ea73

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

PFE/PDS/Assignment 8.5

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"""
2+
Open the file mbox-short.txt and read it line by line. When you find a line that starts with 'From ' like the following line:
3+
4+
From stephen.marquard@uct.ac.za Sat Jan 5 09:14:16 2008
5+
6+
You will parse the From line using split() and print out the second word in the line (i.e. the entire address of the person who sent the message). Then print out a count at the end.
7+
Hint: make sure not to include the lines that start with 'From:'.
8+
9+
You can download the sample data at mbox-short.txt
10+
"""
11+
12+
fname = input("Enter file name: ")
13+
if len(fname) < 1 : fname = "mbox-short.txt"
14+
15+
fh = open(fname)
16+
count = 0
17+
for line in fh:
18+
if line.startswith("From "):
19+
words = line.split()
20+
print(words[1])
21+
count=count+1
22+
print("There were", count, "lines in the file with From as the first word")
23+
24+
25+
26+
27+
28+
"""
29+
Desired Output:
30+
"""

0 commit comments

Comments
 (0)