in my site-packages directory:
============================
# sitecustomize.py (see p.188 of Python for Dummies)
import sys
sys.setdefaultencoding('utf-8')
===============================
With that in place, at the interactive prompt this goes well:
===============================
'utf-8'>>import sys
sys.getdefaultencoding()
.. . . print a[x],>>a = [u'\u91cd', u'\u8981', u'\u6027']
for x in range(3):
.. . .
$B=E(B $BMW(B $B@-(B
===============================>>>
The 3 CJK characters are printed very nicely.
However, when I put the last 3 lines of that code in a script,
============================
a = [u'\u91cd', u'\u8981', u'\u6027']
for x in range(3):
print a[x]
===========================
and redirect the output to a text file, I get
"Traceback (most recent call last):
File "E:\Python25\dev\Untitled1.py", line 3, in ?
print a[x]
UnicodeEncodeError: 'ascii' codec can't encode character u'\u91cd' in
position 0: ordinal not in range(128)"
I thought maybe it would help if I made the first line,
# -*- coding: utf-8 -*-
but that made no difference. Got the same error.
Can someone help me understand what's going on?
Thanks,
Dick Moores
--
my configuration:
Win XP Pro SP2
Python 2.5
wxPython 2.8.1.1 Unicode
Python IDE: Ulipad 3.6