how to make format operator % work with unicode as expected

I V ivlenin at gmail.com
Sun Jan 27 01:08:47 EST 2008


On Sun, 27 Jan 2008 05:32:40 +0000, Peter Pei wrote:
> Yes, it is true that %s already support unicode, and I did not
> contradict that. But it counts the number of bytes instead of
> characters, and makes things like %-20s out of alignment. If you don't
> understand my assertion, please don't argue back and I am only
> interested in answers from those who are qualified.

What version of python are you using? On python 2.4 and 2.5 on linux, 
%-20s counts the characters, not the bytes, or, I think it does. when I 
run:

>>> print u'%-20s|\n%-20s|' % (u'foo bar', u'foo bár')

the output is:

foo bar             |
foo bár             |




More information about the Python-list mailing list