Internationalised email subjects

"Martin v. Löwis" martin at
Fri Jun 22 07:25:42 CEST 2007

bugmagnet at schrieb:
> That's really strange.  The chinese characters I am inputing into the
> post are not being displayed.  Basically, what I am doing is this:
> h = Header('(Some Chinese characters inserted here', 'GB2312')

What encoding do "Some Chinese characters" have at that point?

1. Don't try this at the interactive prompt. It will completely confuse
   you. Instead, use IDLE.
2. In IDLE, put
  # -*- coding: utf-8 -*-
  into the top of the source code file.
3. Write the header as a Unicode string, i.e. with a u prefix
4. Explicitly encode it, such as

h = Header(u'(Some Chinese characters inserted here'.encode('GB2312'),

If you are *not* inserting the characters from the Python source
code directly, go back to my original question: What are the
characters encoded in?


More information about the Python-list mailing list