Print formatted Strings with Umlauts
amy-g-art at cox.net
Wed Feb 11 22:36:24 CET 2004
Upgrading to 2.3 will probablt solve this problem. I am using 2.3 and here
is what I get when I try it.
>>> a = 'äöü'
>>> len (a)
>>> b = '123'
>>> print "%-5s %-5s\n%-5s %-5s" % (a,a,b,b)
"Joerg Lehmann" <joerg.lehmann at mail.com> wrote in message
news:91317660.0402111249.4ccc6e24 at posting.google.com...
> I am using Python 2.2.3 (Fedora Core 1). The problem is, that strings
> 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
> 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
> my results. Is there no way to store umlauts in 1 byte??? What is the
> to print strings containing umlauts in a tabular way (same field width)?
> Joerg Lehmann
More information about the Python-list