Python从文本中分离e-mail

import re,sys  
def Extraction(text):  
    return re.findall(r'[w.]+@[w.]+',text)

if __name__=="__main__":  
    result=''
    for arg in sys.argv[1:]:
        txt_file=open(arg)
        try:
            all_text=txt_file.read()
        except:
            print '%s throw error!' % arg
        else:
            result+=';'.join(Extraction(all_text)) + ';'
            print '%s complete.' % arg
        finally:
            txt_file.close()

    try:
        save_file=open(raw_input('Save path:'),'a')
        save_file.write(result)
    except Exception,e:
        print 'Error:',e
    else:
        print 'Save complete.'
    finally:
        save_file.close()

从文本中分离出e-mail地址,只能在命令行中使用,参数为文本路径(相对路径也可以) 支持多个文件 例如:

C:\Users\Administrator\Desktop\getemail.py 1.txt 1.txt complete. Save path:c:2.txt Save complete.

PS:去除文件中的重复部分