Foreign characters

Discussion in 'Python' started by Tetsuo, Jul 16, 2003.

  1. Tetsuo

    Tetsuo Guest

    How do I get Python to work with foreign characters? When I try to
    print them, I get a unicode error (characters not ASCII). Wasn't
    unicode invented for the express purpose of working with non-ASCII
    characters?
     
    Tetsuo, Jul 16, 2003
    #1
    1. Advertising

  2. Tetsuo

    Peter Hansen Guest

    Tetsuo wrote:
    >
    > How do I get Python to work with foreign characters? When I try to
    > print them, I get a unicode error (characters not ASCII). Wasn't
    > unicode invented for the express purpose of working with non-ASCII
    > characters?


    The FAQ might help:

    http://www.python.org/cgi-bin/faqw.py?req=show&file=faq04.102.htp

    -Peter
     
    Peter Hansen, Jul 16, 2003
    #2
    1. Advertising

  3. Tetsuo

    Dan Bishop Guest

    (Tetsuo) wrote in message news:<>...
    > How do I get Python to work with foreign characters? When I try to
    > print them, I get a unicode error (characters not ASCII).


    # -*- coding: latin-1 -*-
    greeting = "¡Hola! ¿Cómo estás?"
    print greeting

    Or if you actually need to use Unicode strings:

    unicodeString = "a byte string".decode('encoding')
    print unicodeString.encode('encoding')
     
    Dan Bishop, Jul 16, 2003
    #3
  4. Tetsuo

    Paul Boddie Guest

    (Tetsuo) wrote in message news:<>...
    > How do I get Python to work with foreign characters? When I try to
    > print them, I get a unicode error (characters not ASCII). Wasn't
    > unicode invented for the express purpose of working with non-ASCII
    > characters?


    Erm, yes. But the problem you're having is undoubtedly occurring when
    you try to send the Unicode data to your console or terminal. I'd
    recommend using the encode method on your Unicode objects as described
    in the thread "Characters in Python" - use groups.google.com to find
    that discussion.

    On the other hand, if you're using IDLE, I'd suggest trying out
    IDLEfork if you really want to be able to send Unicode data straight
    to the output window. IDLE in Python 2.2.x and below seems to have had
    various issues with Unicode and output, but that's discussed in that
    thread I mentioned.

    I note that the content of the most relevant entry in the Python FAQ
    can be regarded as being somewhat confusing:

    http://www.python.org/cgi-bin/faqw.py?req=show&file=faq04.102.htp

    Notably this statement (in the context of the classic UnicodeError):

    "This error indicates that your Python installation can handle only
    7-bit ASCII strings."

    I doubt that even if one makes the distinction between strings and
    Unicode objects, as I often do myself, that Python has ever been
    unable to handle 8-bit strings. Moreover, the statement gives the
    impression that various Python installations exist which know about
    Unicode (and related encodings) but can't deal with it. Perhaps the
    entry ought to be updated with some of the tips given in previous
    threads, and that more questions and answers need adding to the FAQ
    (which I'm happy to do, by the way, if it's seen as being worthwhile).

    Paul
     
    Paul Boddie, Jul 16, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    389
  2. Replies:
    1
    Views:
    517
    Joerg Jooss
    Aug 22, 2005
  3. rachel cox
    Replies:
    1
    Views:
    2,961
    BarryNL
    Feb 3, 2004
  4. mdjj
    Replies:
    1
    Views:
    644
    Oliver Wong
    Mar 31, 2006
  5. H5N1
    Replies:
    0
    Views:
    445
Loading...

Share This Page