Q:

Python Unicode and MIMEE

Can someone who is way smarter than I tell me what I'm doing wrong..  Shouldn't this simply process...
# 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()

I'm stumped...

A:

Assuming Python 2.* (alas, you don't tell us whether you're on Python 3, but as you're using print as a statement it looks like you aren't): MIMEText" takes a string -- a plain string, NOT a Unicode object.  So, useb.encode('utf-8')as the argument if what you start with is a Unicode objectb`.

