euccas
2/23/2016 - 10:07 PM

[python] count email in a file

Count email in a file

fname = raw_input("Enter file name: ")
if len(fname) < 1 : fname = "mbox-short.txt"

fh = open(fname)
count = 0

for line in fh.readlines():
    if line.startswith('From '):
        print line.split(' ')[1]
        count += 1

print "There were", count, "lines in the file with From as the first word"