Skip to content

Instantly share code, notes, and snippets.

@som983
Last active August 8, 2020 06:48
Show Gist options
  • Save som983/fa2935052190d590033a15671eb674aa to your computer and use it in GitHub Desktop.
Save som983/fa2935052190d590033a15671eb674aa to your computer and use it in GitHub Desktop.
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 a c…
fname = input("Enter file name: ")
fh = open(fname)
count = 0
for line in fh:
line=line.rstrip()
if line.startswith('From:'):
continue
if not line.startswith('From'):
continue
words=line.split()
email = words[1]
count=count+1
print(email)
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