python
  • email
  • unicode
  • 2009-09-11 54 views 0 likes 
    0

    可有人谁比我告诉我我在做什么错误的方式更聪明..不应该只是这个过程......Python的Unicode和MIMEE

    # encoding: utf-8 
    from email.MIMEText import MIMEText 
    
    msg = MIMEText("hi") 
    msg.set_charset('utf-8') 
    print msg.as_string() 
    
    a = 'Ho\xcc\x82tel Ste\xcc\x81phane ' 
    b = unicode(a, "utf-8") 
    
    print b 
    
    msg = MIMEText(b) 
    msg.set_charset('utf-8') 
    print msg.as_string() 
    

    我难倒...

    回答

    2

    假设Python 2. *(可惜,您不告诉我们您是否在Python 3上,但是您使用print作为声明,看起来好像不是):MIMEText" takes a string -- a plain string, NOT a Unicode object. So, use b.encode('utf -8')as the argument if what you start with is a Unicode object b`。

    +0

    谢谢你钉了它! – rh0dium 2009-09-14 18:26:55

    相关问题