how to make format operator % work with unicode as expected
Steven D'Aprano
steve at REMOVE-THIS-cybersource.com.au
Sun Jan 27 02:42:00 EST 2008
On Sun, 27 Jan 2008 05:32:40 +0000, Peter Pei wrote:
> You didn't understand my question, but thanks any way.
>
> 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.
I understand your assertion. I think it is nonsense.
>>> def test():
... print "12345678901234567890 +"
... print "%-20s +" % "Plain ASCII"
... print u"%-20s +" % u"Les misérables-\320\321\322"
...
>>> test()
12345678901234567890 +
Plain ASCII +
Les misérables-ÐÑÒ +
--
Steven
More information about the Python-list
mailing list