printing list containing unicode string

Xah Lee xah at xahlee.org
Tue Sep 11 00:39:14 CEST 2007


Google groups seems to be stripping my quotation marks    lately.
Here's a retry to post my previous message.

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

Xah Lee wrote:
  
  If i have a nested list, where the atoms are unicode strings, e.g.
  # -*- coding: utf-8 -*-
  ttt=[[u"→",u"↑"], [u"αβγ"],...]
  print ttt

  how can i print it without getting the u'\u1234' notation?
  i.e. i want it print just like this: [[u"→"], ...]
  

Carsten Haese wrote:
  
  It's not quite clear why you want to do this, but this is how you
  could do it:

  print repr(ttt).decode("unicode_escape").encode("utf-8")
  

Super! Thanks a lot.

About why i want to... i think it's just simpler and easier on the
eye?

here's a example output from my program:
[[u' ', 1022], [u'↑', 472], [u' ', 128], [u'→w', 300], [u'→s', 12],
[u'→|', 184],...]

wouldn't it be preferable if Python print like this by default...

  Xah
  x... at xahlee.orghttp://xahlee.org/




More information about the Python-list mailing list