Created
October 7, 2017 12:54
-
-
Save MichelleDalalJian/341754de0175074cffb59ab3490da032 to your computer and use it in GitHub Desktop.
8.5 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: From [email protected] Sat Jan 5 09:14:16 2008 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…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fhand = open("mbox-short.txt") | |
count = 0 | |
for line in fhand: | |
line = line.rstrip() | |
if line == "": continue | |
words = line.split() | |
if words[0] !="From": continue | |
print(words[1]) | |
count = count+1 | |
print ("There were", count, "lines in the file with From as the first word") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
if you are prompting the user to enter the file name, you don't need again to assign the file name. Compare my image below....