Print formatted Strings with Umlauts
Joerg Lehmann
joerg.lehmann at mail.com
Wed Feb 11 15:49:29 EST 2004
I am using Python 2.2.3 (Fedora Core 1). The problem is, that strings containing
umlauts do not work as I would expect. Here is my example:
>>> a = 'äöü'
>>> b = '123'
>>> print "%-5s %-5s\n%-5s %-5s" % (a,a,b,b)
äöü äöü
123 123
I would expect, that the displayed width of a or b is the same: 5 characters.
I also see, that len(a) is 6 (2 bytes per umlaut), whereas len(b) is 3:
>>> print len(a), len(b)
6 3
I have tried to set the encoding in site.py to 'latin-1', but it did not change
my results. Is there no way to store umlauts in 1 byte??? What is the right way
to print strings containing umlauts in a tabular way (same field width)?
Thanks!
--
Joerg Lehmann
More information about the Python-list
mailing list