[Tutor] Unicode issues
klappnase at freenet.de
Thu Feb 24 21:10:21 CET 2005
On Thu, 24 Feb 2005 07:51:04 -0500
Kent Johnson <kent37 at tds.net> wrote:
> Michael Lange wrote:
> > I *thought* I would have to convert the user input which might be any encoding back into
> > byte string first
> How are you getting the user input? Is it from the console or from a GUI?
It's a (Tkinter) gui, but anyway, I think I now understand why this idea is total nonsense.
> If your intent is to create a unicode string, try this:
> if not isinstance(result, unicode):
> result = result.decode(sys.stdin.encoding)
Ok, user input must be checked whether it's unicode or not and if necessary be decoded to
unicode with system encoding. For internal operations I should then use only unicode strings
and if I need to print something to stdout I must encode it again with system encoding, right?
> This article gives a lot of good background:
> I have written an essay about console encoding issues. At the end there is a collection of links to
> more general Python and Unicode articles.
That's great! Exactly the kind of articles I've been looking for but couldn't find.
More information about the Tutor