Unicode and exception strings

Terry Carroll carroll at tjc.com
Fri Jan 9 20:48:39 CET 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

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

     _display_text = _display_text + "%s\n" % line
  except UnicodeDecodeError:
         # 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