In my case, your example worked as it should, printing beautiful Unicode.
But sometimes you have a lot of problems with the exception stack printed without (or with escaped / inverse characters) unicode characters. You can overcome the obstacle and print regular messages.
Example exit problem (Python 2.7, linux):
# -*- coding: utf-8 -*- desc = u'something bad with field ¾' raise SyntaxError(desc.encode('utf-8', 'replace'))
It will only print a truncated or screwed message:
~/.../sources/C_patch$ python SO.py Traceback (most recent call last): File "SO.py", line 25, in <module> raise SyntaxError(desc) SyntaxError
To see immutable unicode, you can encode it to raw bytes and throw exceptions into the object:
# -*- coding: utf-8 -*- desc = u'something bad with field ¾' raise SyntaxError(desc.encode('utf-8', 'replace'))
This time you will see the full message:
~/.../sources/C_patch$ python SO.py Traceback (most recent call last): File "SO.py", line 3, in <module> raise SyntaxError(desc.encode('utf-8', 'replace')) SyntaxError: something bad with field ¾
You can do value.encode('utf-8', 'replace') in your constructor if you want, but with a system exception, you will have to do this in the raise , as in the example.
The hint is here: Overcoming disappointment: using unicode correctly in python2 (there is a large library with many helpers, and all of them can be divided into the above example).