1

I'm tring to get a beautiful list of my song info. "beautiful" means song names should occupy fixed width, like this:

songname1       singer1
songname2_xx    singer2

this code works for chars whose width is one character width

file.write(u'{:<30}'.format(title).encode('utf-8'))
file.write(artist.encode('utf-8') + '\n')

But there are non-ascii chars that are wider:

Cycle                         阿保剛
渐渐被你吸引                        FIELD OF VIEW

what should I do to format strings like that?
Maybe iterating over all chars in a string and count the number of Chinese/Japanese characters. But I don't know exactly how to do this, and apparently it's error-prone.
Thank you!

laike9m
  • 18,344
  • 20
  • 107
  • 140
  • 1
    Related: [Checking a character is fullwidth or halfwidth in Python](http://stackoverflow.com/q/23058564), [Programmatically tell if a Unicode character takes up more than one character space in a terminal](http://stackoverflow.com/q/7086856), [how to control output format when chinese characters and ascii mixed?](http://stackoverflow.com/q/23320148) – Martijn Pieters May 08 '14 at 15:47
  • Writing to a file, however, you can *never* control what font is going to be used for those characters. It really depends on the font how much space the full width Asian characters will take up exactly. – Martijn Pieters May 08 '14 at 15:47

0 Answers0