Unicode string output

Michael Hudson mwh21 at cam.ac.uk
Sun Jan 21 12:30:32 EST 2001


Michael =?iso-8859-1?Q?Str=F6der?= <michael at stroeder.com> writes:

> Michael Hudson wrote:
> > 
> > "Alexander Kostyrkin" <avkost66 at f4.dion.ne.jp> writes:
> > 
> > > Surprisingly printing a unicode string that contains a Japanese kanji
> > > character raises an exception
> > > For example
> > >
> > >     print u"\u55f4"
> > > UnicodeError: ASCII encoding error: ordinal not in range(128)
> > >
> > 
> > print u"\u55f4".encode('kanji')
> 
> How about this?
> 
> >>> u"\u55f4".encode('utf-8')
> '\345\227\264'

Indeed.  The answer is, I guess, "it depends", hence why Python forces
you to decide rather than assuming it knows what you're trying to do.

Cheers,
M.

-- 
  I'm sorry, was my bias showing again? :-) 
                                      -- William Tanksley, 13 May 2000



More information about the Python-list mailing list