I'll start by saying that I've already seen this post: Strange python print behavior with unicode, but the solution offered there (using PYTHONIOENCODING) didn't work for me.
Here's my issue:
Python 2.6.5 (r265:79063, Apr 9 2010, 11:16:46)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-44)] on linux2
>>> a = u'\xa6'
>>> print a
¦
works just fine, however:
>>> sys.stdout.write(a)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
UnicodeEncodeError: 'ascii' codec can't encode character u'\xa6' in position 0: ordinal not in range(128)
throws an error. The post I linked to at the top suggests that this is because the default console encoding is 'ascii'. However, in my case it's not:
>>> sys.stdout.encoding
'UTF-8'
So any thoughts on what's at work here and how to fix this issue?
Thanks D.