how to make format operator % work with unicode as expected

Peter Pei yantao at telus.com
Sun Jan 27 10:56:14 EST 2008


"I V" <ivlenin at gmail.com> wrote in message 
news:PdVmj.1467$uE.1363 at newssvr22.news.prodigy.net...
> 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,
2.5.2 on windows, if you have tested linux, maybe... windows is the issue?
> %-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