how to print unicode structures?

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

    #1

    how to print unicode structures?

    Imagine you have some list that looks like
    ('unicode', 'not-acii', 'russian') and contains characters not from
    acsii. or list of dicts, or dict of dicts.

    how can I print it? not on by one, with "for" - but with just a simple
    print? My debugging would be MUCH simpler.

    Now when I try print or pprint that variable I get a page full of
    '\xe4\xeb\xa2\x a0\xe6\xe3\xaa\ xe6\xe3\xaa' and so on.

    I use Python 2.4, Fedora Linux, UTF-8 locale
  • Serge Orlov

    #2
    Re: how to print unicode structures?

    Timothy Babytch wrote:[color=blue]
    > Imagine you have some list that looks like
    > ('unicode', 'not-acii', 'russian') and contains characters not from
    > acsii. or list of dicts, or dict of dicts.
    >
    > how can I print it? not on by one, with "for" - but with just a simple
    > print? My debugging would be MUCH simpler.[/color]

    I think the best (in terms of time) way to do it is to copy pprint.py
    to upprint.py and hack it.
    [color=blue]
    >
    > Now when I try print or pprint that variable I get a page full of
    > '\xe4\xeb\xa2\x a0\xe6\xe3\xaa\ xe6\xe3\xaa' and so on.[/color]

    It looks like bytes, you should get rid of them as soon as possible. If you're not looking for speed hacks, as a rule of thumb you
    should convert bytes to unicode characters as soon as possible. When I try to print Russian characters I get unicode escapes (\u)
    not byte escapes (\x) like you:[color=blue][color=green][color=darkred]
    >>> print unicode([u'ÁÂ×'])[/color][/color][/color]
    [u'\u0430\u0431\ u0432']

    Serge.


    Comment

    • Serge Orlov

      #3
      Re: how to print unicode structures?

      Serge Orlov wrote:[color=blue][color=green][color=darkred]
      >>>> print unicode([u'ÁÂ×'])[/color][/color]
      > [u'\u0430\u0431\ u0432']
      >[/color]
      Oops, Outlook Express has screwed the encoding, one more evidence that printing unicode is hard :)
      I hope this time, the message will be with real Russian characters instead of Latin ones.

      Serge.


      Comment

      Working...