As per p. 188 of Python for Dummies, I've created a sitecustomize.py
in my site-packages directory:
# sitecustomize.py (see p.188 of Python for Dummies)
With that in place, at the interactive prompt this goes well:
>>> import sys . . . print a[x],
>>> a = [u'\u91cd', u'\u8981', u'\u6027']
>>>for x in range(3):
. . .
? ? ?
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):
and redirect the output to a text file, I get
"Traceback (most recent call last):
File "E:\Python25\dev\Untitled1.py", line 3, in ?
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?
Win XP Pro SP2
wxPython 220.127.116.11 Unicode
Python IDE: Ulipad 3.6