how to make format operator % work with unicode as expected

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

    how to make format operator % work with unicode as expected

    I am using things like "%-20s%-60s%-10s" in tkinter listbox to make it look
    like a table, with mono sized font like lucie system. But this does not work
    with data contains "Les misérables", because it is unicode, and one byte is
    not neccessary one character. Now how can I resolve this issue?

    My issue is "how to make format operator % work with unicode as expected",
    and has nothing to do with tkinter. If I want to use a table widget or
    something, I can. But that's not the question.

  • Peter Pei

    #2
    Re: how to make format operator % work with unicode as expected

    I probably should mention that what I want is to make all parts of the
    string aligned, and look like table. I am not looking for other ways to make
    it table-alike, but only interested in making % work with unicode -counting
    characters not bytes...

    Comment

    • Steven D'Aprano

      #3
      Re: how to make format operator % work with unicode as expected

      On Sun, 27 Jan 2008 04:06:45 +0000, Peter Pei wrote:
      I probably should mention that what I want is to make all parts of the
      string aligned, and look like table. I am not looking for other ways to
      make it table-alike, but only interested in making % work with unicode
      -counting characters not bytes...
      % already works with unicode. Just give it unicode arguments:

      >>print u"x y z %s 1 2 3" % u"Les misérables"
      x y z Les misérables 1 2 3


      --
      Steven

      Comment

      • Peter Pei

        #4
        Re: how to make format operator % work with unicode as expected

        For sure I can calculate the number of characters and do the padding myself,
        but what's the point, and i surely hope that python does it for me.
        ============
        "Peter Pei" <yantao@telus.c omwrote in message
        news:cjTmj.4361 0$fj2.37903@edt nps82...
        >I am using things like "%-20s%-60s%-10s" in tkinter listbox to make it look
        >like a table, with mono sized font like lucie system. But this does not
        >work with data contains "Les misérables", because it is unicode, and one
        >byte is not neccessary one character. Now how can I resolve this issue?
        >
        My issue is "how to make format operator % work with unicode as expected",
        and has nothing to do with tkinter. If I want to use a table widget or
        something, I can. But that's not the question.

        Comment

        • John Machin

          #5
          Re: how to make format operator % work with unicode as expected

          On Jan 27, 3:06 pm, "Peter Pei" <yan...@telus.c omwrote:
          I probably should mention that what I want is to make all parts of the
          string aligned, and look like table. I am not looking for other ways to make
          it table-alike, but only interested in making % work with unicode -counting
          characters not bytes...
          Can you show some *code* that demonstrates the alleged problem?
          E.g. len("<some format>" % some_unicode) != expected_len

          Reading this may help:


          Comment

          • Diez B. Roggisch

            #6
            Re: how to make format operator % work with unicode as expected

            Peter Pei schrieb:
            I am using things like "%-20s%-60s%-10s" in tkinter listbox to make it
            look like a table, with mono sized font like lucie system. But this does
            not work with data contains "Les misérables", because it is unicode, and
            one byte is not neccessary one character. Now how can I resolve this issue?
            By learning that unicode is not UTF-8, instead of insulting others of
            being incompetent.


            Diezz

            Comment

            Working...