On Wed, Aug 27, 2008 at 9:59 PM, Yang <[EMAIL PROTECTED]> wrote: > Hello, > I am trying to print out the hole unicode char list in window! form > 0-65535. > I use the winxp in simple chinese LOCAL! the ascii form 0-127 and CJK chars > form > 0X4E00-0X9FA4 can be print out! Other ucode chars case this error > "UnicodeEncodeError: 'gbk' codec can't encode character u'\u9fa6' in position > 0" > > my code is here: > for i in range(0,65536 ): > uchar=unicode("\u%04X"%i,"unicode-escape")
A simpler way to do this is uchar = unichr(i) > print "%x :"%i,uchar > > how can I achive a hole unicode list? Or can it be done? I guess the error comes from the print statement. (Please include the traceback with error reports.) If so, the problem is that your console can't represent all the characters that you want to print. It looks like your console encoding is 'gbk' and not every unicode character can be represented in this encoding. One way to fix this is to explicitly convert to gbk and tell Python to substitute a ? character for the character that can't be converted. To do this, use the str.encode() method and pass a second argument of 'replace'. Then the whole program becomes for i in range(0, 65536): c = unichr(i).encode('gbk', 'replace') print c Another solution might be to change your console to UTF-8 encoding, if that is possible on your computer. If your goal is to see the characters, the resources at Unicode.org might be more help, for example: http://www.unicode.org/charts/ Kent _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor