Hi, "Erik Max Francis" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > 7stud wrote: > >> Based on this example and the error: >> >> ----- >> u_str = u"abc\u9999" >> print u_str >> >> UnicodeEncodeError: 'ascii' codec can't encode character u'\u9999' in >> position 3: ordinal not in range(128) >> ------ >> >> it looks like when I try to display the string, the ascii decoder >> parses each character in the string and fails when it can't convert a >> numerical code that is higher than 127 to a character, i.e. the >> character \u9999. > > If you try to print a Unicode string, then Python will attempt to first > encode it using the default encoding for that file. Here, it's apparent > the default encoding is 'ascii', so it attempts to encode it into ASCII, > which it can't do, hence the exception.
If you want to change the default encoding of your stdout and stderr, you can do something like this: import codecs, sys sys.stdout = codecs.getwriter('utf-8')(sys.stdout) sys.stderr = codecs.getwriter('utf-8')(sys.stderr) After doing this, print u_str will work as expected (when using an utf-8 terminal) - Sander -- http://mail.python.org/mailman/listinfo/python-list