Help for unicode

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Noixe

    Help for unicode

    Hello,

    I'm italian and i not speak a good english. My problem is this:

    Why this istruction:

    print u"\u00" + str(41)

    generate an error and this:

    print u"\u0041" no?


    Can I use all 65536 symbols of unicode in my program? For example, I need to
    use the mathematic symbol of void set. It has a 0198 number in a table of
    symbol that there is in Windows.

    Thanks
    --
    Noixe


  • Irmen de Jong

    #2
    Re: Help for unicode

    Noixe wrote:[color=blue]
    > Why this istruction:
    >
    > print u"\u00" + str(41)
    >
    > generate an error and this:
    >
    > print u"\u0041" no?[/color]

    because they are doing very different things.
    The first is first evaluating u"\u00" and only
    if that succeeds (but it doesn't) add the string
    "41" at the end.

    The second is evaluating the unicode escape
    sequence \u0041 that is part of the string.

    You cannot combine strings like that to form
    arbitrary unicode escape sequences. Try this instead;

    some_variable=0 x0041

    print unichr(some_var iable)

    [color=blue]
    > Can I use all 65536 symbols of unicode in my program? For example, I need to
    > use the mathematic symbol of void set. It has a 0198 number in a table of
    > symbol that there is in Windows.[/color]

    No problem to use all unicode symbols.

    But I don't think the empty set symbols is Unicode code point U+0198:
    [color=blue][color=green][color=darkred]
    >>> import unicodedata
    >>> unicodedata.nam e(u'\u0198')[/color][/color][/color]
    'LATIN CAPITAL LETTER K WITH HOOK'[color=blue][color=green][color=darkred]
    >>> unicodedata.loo kup("EMPTY SET")[/color][/color][/color]
    u'\u2205'

    So I think you should use U+2205 instead?
    --Irmen

    Comment

    • Noixe

      #3
      Re: Help for unicode

      Thanks!


      Comment

      • Noixe

        #4
        Re: Help for unicode

        "Irmen de Jong" <irmen@-NOSPAM-REMOVETHIS-xs4all.nl> ha scritto:

        If I write:

        print u'\u2205'

        I have this error: UnicodeError: ASCII encoding error: ordinal not in
        range(128)


        Why? I must include some module?

        --
        Noixe


        Comment

        • Gerhard Häring

          #5
          Re: Help for unicode

          Noixe wrote:[color=blue]
          > Hello,
          >
          > I'm italian and i not speak a good english. My problem is this:
          >
          > Why this istruction:
          >
          > print u"\u00" + str(41)
          >
          > generate an error and this:
          >
          > print u"\u0041" no?[/color]

          That's because Unicode literals (\uxxxx) are interpreted at compile
          time, not at runtime.
          [color=blue]
          > Can I use all 65536 symbols of unicode in my program? For example, I need to
          > use the mathematic symbol of void set. It has a 0198 number in a table of
          > symbol that there is in Windows.[/color]

          I don't know which symbol this is in Unicode, maybe somebody else can?

          -- Gerhard


          Comment

          • Martin v. Löwis

            #6
            Re: Help for unicode

            "Noixe" <NoixeTOGLIMI@h otmail.com> writes:
            [color=blue]
            > print u'\u2205'
            >
            > I have this error: UnicodeError: ASCII encoding error: ordinal not in
            > range(128)
            >
            >
            > Why? I must include some module?[/color]

            No. Just don't print it:
            [color=blue][color=green][color=darkred]
            >>> x=u'\u2205'
            >>> x[/color][/color][/color]
            u'\u2205'

            The character U+2205 is EMPTY SET; your terminal is not capable of
            displaying that symbol.

            Regards,
            Martin

            Comment

            • Noixe

              #7
              Re: Help for unicode

              "Martin v. Löwis" <martin@v.loewi s.de> ha scritto:
              [color=blue]
              > The character U+2205 is EMPTY SET; your terminal is not capable of
              > displaying that symbol.[/color]

              Ah... and not exist one solution?

              --
              Noixe


              Comment

              • Irmen de Jong

                #8
                Re: Help for unicode

                Noixe wrote:
                [color=blue][color=green]
                >>The character U+2205 is EMPTY SET; your terminal is not capable of
                >>displaying that symbol.[/color]
                >
                >
                > Ah... and not exist one solution?[/color]

                Change your output to something that *does* support displaying
                U+2205, such as a HTML document that you then read with a
                decent web browser.

                Or you could use 'LATIN SMALL LETTER O WITH STROKE' instead,
                U+00f8 (u'\xf8'). It looks very similar to the EMPTY SET symbol,
                and because it is just a normal letter instead of a mathematical
                symbol, it is much more likely to be supported by your terminal.

                --Irmen

                Comment

                • Martin v. Löwis

                  #9
                  Re: Help for unicode

                  Noixe wrote:[color=blue][color=green]
                  >>The character U+2205 is EMPTY SET; your terminal is not capable of
                  >>displaying that symbol.[/color]
                  >
                  >
                  > Ah... and not exist one solution?[/color]

                  What kind of output would you like to get? I'm sure it can be arranged,
                  if your computer hardware is good enough. However, you have to tell us
                  what solution you want.

                  Regards,
                  Martin

                  Comment

                  • Noixe

                    #10
                    Re: Help for unicode

                    "Martin v. Löwis" <martin@v.loewi s.de> ha scritto:

                    No problem. It's no so important.

                    --
                    Noixe


                    Comment

                    • David Eppstein

                      #11
                      Re: Help for unicode

                      In article <2perb.101236$v O5.3965040@twis ter1.libero.it> ,
                      "Noixe" <NoixeTOGLIMI@h otmail.com> wrote:
                      [color=blue]
                      > If I write:
                      >
                      > print u'\u2205'
                      >
                      > I have this error: UnicodeError: ASCII encoding error: ordinal not in
                      > range(128)
                      >
                      >
                      > Why? I must include some module?[/color]

                      You have to specify which encoding you want to print it in.
                      E.g.[color=blue][color=green][color=darkred]
                      >>> print u'\u2205'.encod e('utf8')[/color][/color][/color]

                      Of course this will only work if the output stream you print to is set
                      up to use that encoding...

                      --
                      David Eppstein http://www.ics.uci.edu/~eppstein/
                      Univ. of California, Irvine, School of Information & Computer Science

                      Comment

                      Working...