newbie: unicode

Fredrik Lundh fredrik at pythonware.com
Tue Jan 7 09:01:39 CET 2003


Jan Weingärtner wrote:

> I'm just beginning to learn Python.
> My tutorial gives an example how to convert a unicode
> string to utf-8:
>
> >>> u"äöü".encode('utf-8')
> '\xc3\xa4\xc3\xb6\xc3\xbc'
>
> If i try to execute this command, i get the error message:
> "UnicodeError: ASCII encoding error: ordinal not in range(128)"
>
> Why?

how are you executing that command?

there's no way that piece of code can give that error message,
as long as ">>>" is an ordinary Python 2.x interpreter prompt, and
you haven't been hacking around in the site configuration files...

on the other hand,

>>> "äöü".encode('utf-8')

does give you that message.

more here:

    http://effbot.org/zone/unicode-objects.htm
    http://www.jorendorff.com/articles/unicode/python.html
    http://www.reportlab.com/i18n/python_unicode_tutorial.html
    http://www.python.org/doc/current/ref/strings.html

</F>








More information about the Python-list mailing list