PyCon 2011 - Hidden Treasures of the Python Standard Library - 解析电子邮件地址

 

本作品采用知识共享署名-非商业性使用-相同方式共享 3.0 Unported许可协议进行许可。允许非商业转载,但应注明作者及出处。


作者:liuyuan_jq

2011-03-30

 

 

完整源码

 

 

#!/usr/bin/env python # encoding: utf-8 """Parse email addresses format method was introduced in python 3.0 and backported only to 2.6 For Python versions below 2.6, use the % operator """ import email.utils import sys for addr in [ 'Doug Hellmann <[email protected]>', '[email protected]', ]: addr_parsed = email.utils.parseaddr(addr) if sys.version_info < (2, 6): print "%15s" % (addr_parsed[0],), addr_parsed[1] else: print '{:15} {}'.format(*addr_parsed)  

 

运行结果

 

 

Doug Hellmann [email protected] [email protected] 

 

 


 

你可能感兴趣的:(PyCon 2011 - Hidden Treasures of the Python Standard Library - 解析电子邮件地址)