FAQ
Hi.

I'm learning python. python 2.6.6 on ubuntu 10.10 I'm swedish so I try to use
unicode to get swedish characters. I've checked wikipedia.
utf-8 is said to be an unicode encoding..

this is the test program:

# -*- coding: utf-8 -*-

import readline

s=raw_input(u'M?nadsl?n:')

and this is the output:

Traceback (most recent call last):
File "test_uni.py", line 5, in <module>
s=raw_input(u'M?nadsl?n:')
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe5' in position 1: ordinal not in range(128)

I'm doing something wrong...

Mikael


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20101120/3373e84d/attachment.html>

Search Discussions

  • Stefan Sonnenberg-Carstens at Nov 20, 2010 at 7:47 am

    Am 20.11.2010 06:53, schrieb Mikael B:
    Hi.

    I'm learning python. python 2.6.6 on ubuntu 10.10 I'm swedish so I try
    to use
    unicode to get swedish characters. I've checked wikipedia.
    utf-8 is said to be an unicode encoding..

    this is the test program:

    # -*- coding: utf-8 -*-

    import readline

    s=raw_input(u'M?nadsl?n:')

    and this is the output:

    Traceback (most recent call last):
    File "test_uni.py", line 5, in <module>
    s=raw_input(u'M?nadsl?n:')
    UnicodeEncodeError: 'ascii' codec can't encode character u'\xe5' in
    position 1: ordinal not in range(128)

    I'm doing something wrong...

    Mikael
    Your console is not unicode ready.
    Please take a look at the locale command and vars like
    LC_ALL, LC_LANG etc.
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: <http://mail.python.org/pipermail/python-list/attachments/20101120/fc3d4982/attachment.html>
    -------------- next part --------------
    A non-text attachment was scrubbed...
    Name: stefan_sonnenberg.vcf
    Type: text/x-vcard
    Size: 223 bytes
    Desc: not available
    URL: <http://mail.python.org/pipermail/python-list/attachments/20101120/fc3d4982/attachment.vcf>
  • Mikael B at Nov 20, 2010 at 7:49 am
    Date: Sat, 20 Nov 2010 08:47:18 +0100
    From: stefan.sonnenberg at pythonmeister.com
    To: mback1 at live.se
    CC: python-list at python.org
    Subject: Re: try to use unicode







    Meddelandetext


    Am 20.11.2010 06:53, schrieb Mikael B:


    Hi.



    I'm learning python. python 2.6.6 on ubuntu 10.10 I'm swedish so I
    try to use

    unicode to get swedish characters. I've checked wikipedia.

    utf-8 is said to be an unicode encoding..



    this is the test program:



    # -*- coding: utf-8 -*-



    import readline



    s=raw_input(u'M?nadsl?n:')



    and this is the output:



    Traceback (most recent call last):

    File "test_uni.py", line 5, in <module>

    s=raw_input(u'M?nadsl?n:')

    UnicodeEncodeError: 'ascii' codec can't encode character u'\xe5'
    in position 1: ordinal not in range(128)



    I'm doing something wrong...



    Mikael




    Your console is not unicode ready.

    Please take a look at the locale command and vars like

    LC_ALL, LC_LANG etc.



    Aha... Ok,thank you



    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: <http://mail.python.org/pipermail/python-list/attachments/20101120/71c0b283/attachment.html>
  • Mikael B at Nov 20, 2010 at 3:10 pm
    From: mback1 at live.se
    To: python-list at python.org
    Subject: RE: try to use unicode
    Date: Sat, 20 Nov 2010 08:49:59 +0100










    Date: Sat, 20 Nov 2010 08:47:18 +0100
    From: stefan.sonnenberg at pythonmeister.com
    To: mback1 at live.se
    CC: python-list at python.org
    Subject: Re: try to use unicode







    Meddelandetext


    Am 20.11.2010 06:53, schrieb Mikael B:


    Hi.



    I'm learning python. python 2.6.6 on ubuntu 10.10 I'm swedish so I
    try to use

    unicode to get swedish characters. I've checked wikipedia.

    utf-8 is said to be an unicode encoding..



    this is the test program:



    # -*- coding: utf-8 -*-



    import readline



    s=raw_input(u'M?nadsl?n:')



    and this is the output:



    Traceback (most recent call last):

    File "test_uni.py", line 5, in <module>

    s=raw_input(u'M?nadsl?n:')

    UnicodeEncodeError: 'ascii' codec can't encode character u'\xe5'
    in position 1: ordinal not in range(128)



    I'm doing something wrong...



    Mikael




    Your console is not unicode ready.

    Please take a look at the locale command and vars like

    LC_ALL, LC_LANG etc.



    Aha... Ok,thank you

    ----------------

    But I checked this out.. Gnome terminal is set to 'unicode utf-8 encoding'
    and locale command returns

    LANG=sv_SE.utf8
    LC_CTYPE="sv_SE.utf8"
    LC_NUMERIC="sv_SE.utf8"
    LC_TIME="sv_SE.utf8"
    LC_COLLATE="sv_SE.utf8"
    LC_MONETARY="sv_SE.utf8"
    LC_MESSAGES="sv_SE.utf8"
    LC_PAPER="sv_SE.utf8"
    LC_NAME="sv_SE.utf8"
    LC_ADDRESS="sv_SE.utf8"
    LC_TELEPHONE="sv_SE.utf8"
    LC_MEASUREMENT="sv_SE.utf8"
    LC_IDENTIFICATION="sv_SE.utf8"
    LC_ALL=

    if I remove the u before strings its works.. it must be a 8-bit subset
    of utf-8?

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedNov 20, '10 at 5:53a
activeNov 20, '10 at 3:10p
posts4
users2
websitepython.org

People

Translate

site design / logo © 2022 Grokbase