Unicode and exception strings

Terry Carroll carroll at tjc.com
Fri Jan 9 14:48:39 EST 2004


On Fri, 09 Jan 2004 19:44:21 GMT, Terry Carroll <carroll at tjc.com> wrote:

>In one program I have that occasionally runs into a line that includes
>some (UTF-8) Unicode-encoded Chinese characters , I have something like
>this:

Sorry, a stray parenthesis crept in here (since this is a pared down
version of my actual code).  It should read:


  try:
     _display_text = _display_text + "%s\n" % line
  except UnicodeDecodeError:
     try:
         # decode those UTF8 nasties
         _display_text = _display_text + "%s\n" % line.decode('utf-8')
     except UnicodeDecodeError:
         # if that still doesn't work, punt
         # (I don't think we'll ever reach this, but just in case)
         _display_text = _display_text + "%s\n" % repr(line)

> I don't know if this will help you or not.  




More information about the Python-list mailing list