从信息中提取发件人的邮箱

数据:点击打开链接

输出样例:

[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
There were 27 lines in the file with From as the first word

代码:

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

fh = open(fname)
count = 0
for line in fh:
    line = line.strip()
    words = line.split()
    if len(words):
        if words[0]=='From':
            print (words[1])
            count = count + 1
print "There were", count, "lines in the file with From as the first word"

你可能感兴趣的:(Python旅途)