Skip to content

Instantly share code, notes, and snippets.

@zcakzwa
Last active July 5, 2016 04:20
Show Gist options
  • Save zcakzwa/0cc15a79ac4b36b8151236bce2e3fa8e to your computer and use it in GitHub Desktop.
Save zcakzwa/0cc15a79ac4b36b8151236bce2e3fa8e 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…
fname = raw_input("Enter file name: ")
fh = open(fname)
count=0
for line in fh:
if not line.startswith("From "):
continue
else:
list=line.split()
print list[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